Coverage Report

Created: 2022-07-08 09:39

/home/mdboom/Work/builds/cpython/Objects/typeobject.c
Line
Count
Source (jump to first uncovered line)
1
/* Type object implementation */
2
3
#include "Python.h"
4
#include "pycore_call.h"
5
#include "pycore_code.h"          // CO_FAST_FREE
6
#include "pycore_compile.h"       // _Py_Mangle()
7
#include "pycore_initconfig.h"    // _PyStatus_OK()
8
#include "pycore_moduleobject.h"  // _PyModule_GetDef()
9
#include "pycore_object.h"        // _PyType_HasFeature()
10
#include "pycore_pyerrors.h"      // _PyErr_Occurred()
11
#include "pycore_pystate.h"       // _PyThreadState_GET()
12
#include "pycore_typeobject.h"    // struct type_cache
13
#include "pycore_unionobject.h"   // _Py_union_type_or
14
#include "pycore_frame.h"         // _PyInterpreterFrame
15
#include "opcode.h"               // MAKE_CELL
16
#include "structmember.h"         // PyMemberDef
17
18
#include <ctype.h>
19
20
/*[clinic input]
21
class type "PyTypeObject *" "&PyType_Type"
22
class object "PyObject *" "&PyBaseObject_Type"
23
[clinic start generated code]*/
24
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=4b94608d231c434b]*/
25
26
#include "clinic/typeobject.c.h"
27
28
/* Support type attribute lookup cache */
29
30
/* The cache can keep references to the names alive for longer than
31
   they normally would.  This is why the maximum size is limited to
32
   MCACHE_MAX_ATTR_SIZE, since it might be a problem if very large
33
   strings are used as attribute names. */
34
5.78M
#define MCACHE_MAX_ATTR_SIZE    100
35
#define MCACHE_HASH(version, name_hash)                                 \
36
244M
        (((unsigned int)(version) ^ (unsigned int)(name_hash))          \
37
244M
         & ((1 << MCACHE_SIZE_EXP) - 1))
38
39
#define MCACHE_HASH_METHOD(type, name)                                  \
40
244M
    MCACHE_HASH((type)->tp_version_tag, ((Py_ssize_t)(name)) >> 3)
41
#define MCACHE_CACHEABLE_NAME(name)                             \
42
5.78M
        PyUnicode_CheckExact(name) &&                           \
43
5.78M
        PyUnicode_IS_READY(name) &&                             \
44
11.5M
        (PyUnicode_GET_LENGTH(name) <= MCACHE_MAX_ATTR_SIZE)
45
46
// bpo-42745: next_version_tag remains shared by all interpreters because of static types
47
// Used to set PyTypeObject.tp_version_tag
48
static unsigned int next_version_tag = 1;
49
50
typedef struct PySlot_Offset {
51
    short subslot_offset;
52
    short slot_offset;
53
} PySlot_Offset;
54
55
56
static PyObject *
57
slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
58
59
static void
60
clear_slotdefs(void);
61
62
static PyObject *
63
lookup_maybe_method(PyObject *self, PyObject *attr, int *unbound);
64
65
static int
66
slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value);
67
68
/*
69
 * finds the beginning of the docstring's introspection signature.
70
 * if present, returns a pointer pointing to the first '('.
71
 * otherwise returns NULL.
72
 *
73
 * doesn't guarantee that the signature is valid, only that it
74
 * has a valid prefix.  (the signature must also pass skip_signature.)
75
 */
76
static const char *
77
find_signature(const char *name, const char *doc)
78
35.5k
{
79
35.5k
    const char *dot;
80
35.5k
    size_t length;
81
82
35.5k
    if (!doc)
  Branch (82:9): [True: 227, False: 35.3k]
83
227
        return NULL;
84
85
35.3k
    assert(name != NULL);
86
87
    /* for dotted names like classes, only use the last component */
88
35.3k
    dot = strrchr(name, '.');
89
35.3k
    if (dot)
  Branch (89:9): [True: 15.1k, False: 20.1k]
90
15.1k
        name = dot + 1;
91
92
35.3k
    length = strlen(name);
93
35.3k
    if (strncmp(doc, name, length))
  Branch (93:9): [True: 17.6k, False: 17.6k]
94
17.6k
        return NULL;
95
17.6k
    doc += length;
96
17.6k
    if (*doc != '(')
  Branch (96:9): [True: 3.32k, False: 14.3k]
97
3.32k
        return NULL;
98
14.3k
    return doc;
99
17.6k
}
100
101
629k
#define SIGNATURE_END_MARKER         ")\n--\n\n"
102
32.2k
#define SIGNATURE_END_MARKER_LENGTH  6
103
/*
104
 * skips past the end of the docstring's introspection signature.
105
 * (assumes doc starts with a valid signature prefix.)
106
 */
107
static const char *
108
skip_signature(const char *doc)
109
14.3k
{
110
610k
    while (*doc) {
  Branch (110:12): [True: 610k, False: 545]
111
610k
        if ((*doc == *SIGNATURE_END_MARKER) &&
Line
Count
Source
101
610k
#define SIGNATURE_END_MARKER         ")\n--\n\n"
  Branch (111:13): [True: 19.3k, False: 590k]
112
610k
            !strncmp(doc, SIGNATURE_END_MARKER, SIGNATURE_END_MARKER_LENGTH))
Line
Count
Source
101
19.3k
#define SIGNATURE_END_MARKER         ")\n--\n\n"
            !strncmp(doc, SIGNATURE_END_MARKER, SIGNATURE_END_MARKER_LENGTH))
Line
Count
Source
102
19.3k
#define SIGNATURE_END_MARKER_LENGTH  6
  Branch (112:13): [True: 11.1k, False: 8.19k]
113
11.1k
            return doc + SIGNATURE_END_MARKER_LENGTH;
Line
Count
Source
102
11.1k
#define SIGNATURE_END_MARKER_LENGTH  6
114
599k
        if ((*doc == '\n') && (doc[1] == '\n'))
  Branch (114:13): [True: 8.56k, False: 590k]
  Branch (114:31): [True: 2.69k, False: 5.87k]
115
2.69k
            return NULL;
116
596k
        doc++;
117
596k
    }
118
545
    return NULL;
119
14.3k
}
120
121
int
122
_PyType_CheckConsistency(PyTypeObject *type)
123
0
{
124
0
#define CHECK(expr) \
125
0
    do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0)
126
127
0
    CHECK(!_PyObject_IsFreed((PyObject *)type));
Line
Count
Source
125
0
    do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0)
Line
Count
Source
393
0
    _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
  Branch (125:14): [True: 0, False: 0]
  Branch (125:103): [Folded - Ignored]
128
129
0
    if (!(type->tp_flags & Py_TPFLAGS_READY)) {
Line
Count
Source
388
0
#define Py_TPFLAGS_READY (1UL << 12)
  Branch (129:9): [True: 0, False: 0]
130
        /* don't check static types before PyType_Ready() */
131
0
        return 1;
132
0
    }
133
134
0
    CHECK(Py_REFCNT(type) >= 1);
Line
Count
Source
125
0
    do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0)
Line
Count
Source
393
0
    _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
  Branch (125:14): [True: 0, False: 0]
  Branch (125:103): [Folded - Ignored]
135
0
    CHECK(PyType_Check(type));
Line
Count
Source
125
0
    do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0)
Line
Count
Source
393
0
    _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
  Branch (125:14): [True: 0, False: 0]
  Branch (125:103): [Folded - Ignored]
136
137
0
    CHECK(!(type->tp_flags & Py_TPFLAGS_READYING));
Line
Count
Source
125
0
    do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0)
Line
Count
Source
393
0
    _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
  Branch (125:14): [True: 0, False: 0]
  Branch (125:103): [Folded - Ignored]
138
0
    CHECK(type->tp_dict != NULL);
Line
Count
Source
125
0
    do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0)
Line
Count
Source
393
0
    _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
  Branch (125:14): [True: 0, False: 0]
  Branch (125:103): [Folded - Ignored]
139
140
0
    if (type->tp_flags & Py_TPFLAGS_HAVE_GC) {
Line
Count
Source
394
0
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (140:9): [True: 0, False: 0]
141
        // bpo-44263: tp_traverse is required if Py_TPFLAGS_HAVE_GC is set.
142
        // Note: tp_clear is optional.
143
0
        CHECK(type->tp_traverse != NULL);
Line
Count
Source
125
0
    do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0)
Line
Count
Source
393
0
    _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
  Branch (125:14): [True: 0, False: 0]
  Branch (125:103): [Folded - Ignored]
144
0
    }
145
146
0
    if (type->tp_flags & Py_TPFLAGS_DISALLOW_INSTANTIATION) {
Line
Count
Source
369
0
#define Py_TPFLAGS_DISALLOW_INSTANTIATION (1UL << 7)
  Branch (146:9): [True: 0, False: 0]
147
0
        CHECK(type->tp_new == NULL);
Line
Count
Source
125
0
    do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0)
Line
Count
Source
393
0
    _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
  Branch (125:14): [True: 0, False: 0]
  Branch (125:103): [Folded - Ignored]
148
0
        CHECK(PyDict_Contains(type->tp_dict, &_Py_ID(__new__)) == 0);
Line
Count
Source
125
0
    do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0)
Line
Count
Source
393
0
    _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
  Branch (125:14): [True: 0, False: 0]
  Branch (125:103): [Folded - Ignored]
149
0
    }
150
151
0
    return 1;
152
0
#undef CHECK
153
0
}
154
155
static const char *
156
_PyType_DocWithoutSignature(const char *name, const char *internal_doc)
157
33.3k
{
158
33.3k
    const char *doc = find_signature(name, internal_doc);
159
160
33.3k
    if (doc) {
  Branch (160:9): [True: 12.3k, False: 21.0k]
161
12.3k
        doc = skip_signature(doc);
162
12.3k
        if (doc)
  Branch (162:13): [True: 9.22k, False: 3.09k]
163
9.22k
            return doc;
164
12.3k
        }
165
24.1k
    return internal_doc;
166
33.3k
}
167
168
PyObject *
169
_PyType_GetDocFromInternalDoc(const char *name, const char *internal_doc)
170
10.3k
{
171
10.3k
    const char *doc = _PyType_DocWithoutSignature(name, internal_doc);
172
173
10.3k
    if (!doc || *doc == '\0') {
  Branch (173:9): [True: 161, False: 10.1k]
  Branch (173:17): [True: 101, False: 10.0k]
174
262
        Py_RETURN_NONE;
Line
Count
Source
661
262
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
262
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
262
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
262
#  define _Py_CAST(type, expr) ((type)(expr))
175
262
    }
176
177
10.0k
    return PyUnicode_FromString(doc);
178
10.3k
}
179
180
PyObject *
181
_PyType_GetTextSignatureFromInternalDoc(const char *name, const char *internal_doc)
182
2.18k
{
183
2.18k
    const char *start = find_signature(name, internal_doc);
184
2.18k
    const char *end;
185
186
2.18k
    if (start)
  Branch (186:9): [True: 2.02k, False: 165]
187
2.02k
        end = skip_signature(start);
188
165
    else
189
165
        end = NULL;
190
2.18k
    if (!end) {
  Branch (190:9): [True: 304, False: 1.88k]
191
304
        Py_RETURN_NONE;
Line
Count
Source
661
304
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
304
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
304
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
304
#  define _Py_CAST(type, expr) ((type)(expr))
192
304
    }
193
194
    /* back "end" up until it points just past the final ')' */
195
1.88k
    end -= SIGNATURE_END_MARKER_LENGTH - 1;
Line
Count
Source
102
1.88k
#define SIGNATURE_END_MARKER_LENGTH  6
196
1.88k
    assert((end - start) >= 2); /* should be "()" at least */
197
1.88k
    assert(end[-1] == ')');
198
1.88k
    assert(end[0] == '\n');
199
1.88k
    return PyUnicode_FromStringAndSize(start, end - start);
200
2.18k
}
201
202
203
static struct type_cache*
204
get_type_cache(void)
205
238M
{
206
238M
    PyInterpreterState *interp = _PyInterpreterState_GET();
207
238M
    return &interp->type_cache;
208
238M
}
209
210
211
static void
212
type_cache_clear(struct type_cache *cache, PyObject *value)
213
303
{
214
1.24M
    for (Py_ssize_t i = 0; i < (1 << MCACHE_SIZE_EXP); i++) {
Line
Count
Source
30
1.24M
#define MCACHE_SIZE_EXP 12
  Branch (214:28): [True: 1.24M, False: 303]
215
1.24M
        struct type_cache_entry *entry = &cache->hashtable[i];
216
1.24M
        entry->version = 0;
217
1.24M
        Py_XSETREF(entry->name, _Py_XNewRef(value));
Line
Count
Source
339
1.24M
    do {                                        \
340
1.24M
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
1.24M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.24M
#  define _Py_CAST(type, expr) ((type)(expr))
341
1.24M
        (op) = (op2);                           \
342
1.24M
        Py_XDECREF(_py_tmp);                    \
Line
Count
Source
613
1.24M
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
1.24M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.24M
#  define _Py_CAST(type, expr) ((type)(expr))
343
1.24M
    } while (0)
  Branch (343:14): [Folded - Ignored]
218
1.24M
        entry->value = NULL;
219
1.24M
    }
220
303
}
221
222
223
void
224
_PyType_InitCache(PyInterpreterState *interp)
225
278
{
226
278
    struct type_cache *cache = &interp->type_cache;
227
1.13M
    for (Py_ssize_t i = 0; i < (1 << MCACHE_SIZE_EXP); i++) {
Line
Count
Source
30
1.13M
#define MCACHE_SIZE_EXP 12
  Branch (227:28): [True: 1.13M, False: 278]
228
1.13M
        struct type_cache_entry *entry = &cache->hashtable[i];
229
1.13M
        assert(entry->name == NULL);
230
231
1.13M
        entry->version = 0;
232
        // Set to None so _PyType_Lookup() can use Py_SETREF(),
233
        // rather than using slower Py_XSETREF().
234
1.13M
        entry->name = Py_NewRef(Py_None);
Line
Count
Source
639
1.13M
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
1.13M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.13M
#  define _Py_CAST(type, expr) ((type)(expr))
235
1.13M
        entry->value = NULL;
236
1.13M
    }
237
278
}
238
239
240
static unsigned int
241
_PyType_ClearCache(PyInterpreterState *interp)
242
31
{
243
31
    struct type_cache *cache = &interp->type_cache;
244
#if MCACHE_STATS
245
    size_t total = cache->hits + cache->collisions + cache->misses;
246
    fprintf(stderr, "-- Method cache hits        = %zd (%d%%)\n",
247
            cache->hits, (int) (100.0 * cache->hits / total));
248
    fprintf(stderr, "-- Method cache true misses = %zd (%d%%)\n",
249
            cache->misses, (int) (100.0 * cache->misses / total));
250
    fprintf(stderr, "-- Method cache collisions  = %zd (%d%%)\n",
251
            cache->collisions, (int) (100.0 * cache->collisions / total));
252
    fprintf(stderr, "-- Method cache size        = %zd KiB\n",
253
            sizeof(cache->hashtable) / 1024);
254
#endif
255
256
    // Set to None, rather than NULL, so _PyType_Lookup() can
257
    // use Py_SETREF() rather than using slower Py_XSETREF().
258
31
    type_cache_clear(cache, Py_None);
Line
Count
Source
654
31
#define Py_None (&_Py_NoneStruct)
259
260
31
    return next_version_tag - 1;
261
31
}
262
263
264
unsigned int
265
PyType_ClearCache(void)
266
31
{
267
31
    PyInterpreterState *interp = _PyInterpreterState_GET();
268
31
    return _PyType_ClearCache(interp);
269
31
}
270
271
272
void
273
_PyTypes_Fini(PyInterpreterState *interp)
274
272
{
275
272
    struct type_cache *cache = &interp->type_cache;
276
272
    type_cache_clear(cache, NULL);
277
272
    if (_Py_IsMainInterpreter(interp)) {
  Branch (277:9): [True: 103, False: 169]
278
103
        clear_slotdefs();
279
103
    }
280
272
}
281
282
283
void
284
PyType_Modified(PyTypeObject *type)
285
717k
{
286
    /* Invalidate any cached data for the specified type and all
287
       subclasses.  This function is called after the base
288
       classes, mro, or attributes of the type are altered.
289
290
       Invariants:
291
292
       - before Py_TPFLAGS_VALID_VERSION_TAG can be set on a type,
293
         it must first be set on all super types.
294
295
       This function clears the Py_TPFLAGS_VALID_VERSION_TAG of a
296
       type (so it must first clear it on all subclasses).  The
297
       tp_version_tag value is meaningless unless this flag is set.
298
       We don't assign new version tags eagerly, but only as
299
       needed.
300
     */
301
717k
    if (!_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) {
Line
Count
Source
407
717k
#define Py_TPFLAGS_VALID_VERSION_TAG  (1UL << 19)
  Branch (301:9): [True: 526k, False: 190k]
302
526k
        return;
303
526k
    }
304
305
190k
    PyObject *subclasses = type->tp_subclasses;
306
190k
    if (subclasses != NULL) {
  Branch (306:9): [True: 8.57k, False: 181k]
307
8.57k
        assert(PyDict_CheckExact(subclasses));
308
309
8.57k
        Py_ssize_t i = 0;
310
8.57k
        PyObject *ref;
311
29.3k
        while (PyDict_Next(subclasses, &i, NULL, &ref)) {
  Branch (311:16): [True: 20.7k, False: 8.57k]
312
20.7k
            assert(PyWeakref_CheckRef(ref));
313
20.7k
            PyObject *obj = PyWeakref_GET_OBJECT(ref);
Line
Count
Source
56
20.7k
#define PyWeakref_GET_OBJECT(ref) PyWeakref_GET_OBJECT(_PyObject_CAST(ref))
Line
Count
Source
109
20.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.7k
#  define _Py_CAST(type, expr) ((type)(expr))
314
20.7k
            if (obj == Py_None) {
Line
Count
Source
654
20.7k
#define Py_None (&_Py_NoneStruct)
  Branch (314:17): [True: 18.7k, False: 2.03k]
315
18.7k
                continue;
316
18.7k
            }
317
2.03k
            PyType_Modified(_PyType_CAST(obj));
Line
Count
Source
792
2.03k
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
2.03k
#  define _Py_CAST(type, expr) ((type)(expr))
318
2.03k
        }
319
8.57k
    }
320
321
190k
    type->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
Line
Count
Source
407
190k
#define Py_TPFLAGS_VALID_VERSION_TAG  (1UL << 19)
322
190k
    type->tp_version_tag = 0; /* 0 is not a valid version tag */
323
190k
}
324
325
static void
326
229k
type_mro_modified(PyTypeObject *type, PyObject *bases) {
327
    /*
328
       Check that all base classes or elements of the MRO of type are
329
       able to be cached.  This function is called after the base
330
       classes or mro of the type are altered.
331
332
       Unset HAVE_VERSION_TAG and VALID_VERSION_TAG if the type
333
       has a custom MRO that includes a type which is not officially
334
       super type, or if the type implements its own mro() method.
335
336
       Called from mro_internal, which will subsequently be called on
337
       each subclass when their mro is recursively updated.
338
     */
339
229k
    Py_ssize_t i, n;
340
229k
    int custom = !Py_IS_TYPE(type, &PyType_Type);
Line
Count
Source
155
229k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
229k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
229k
#  define _Py_CAST(type, expr) ((type)(expr))
341
229k
    int unbound;
342
343
229k
    if (custom) {
  Branch (343:9): [True: 34.8k, False: 195k]
344
34.8k
        PyObject *mro_meth, *type_mro_meth;
345
34.8k
        mro_meth = lookup_maybe_method(
346
34.8k
            (PyObject *)type, &_Py_ID(mro), &unbound);
Line
Count
Source
374
34.8k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
34.8k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
34.8k
    _PyRuntime.global_objects.NAME
347
34.8k
        if (mro_meth == NULL) {
  Branch (347:13): [True: 0, False: 34.8k]
348
0
            goto clear;
349
0
        }
350
34.8k
        type_mro_meth = lookup_maybe_method(
351
34.8k
            (PyObject *)&PyType_Type, &_Py_ID(mro), &unbound);
Line
Count
Source
374
34.8k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
34.8k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
34.8k
    _PyRuntime.global_objects.NAME
352
34.8k
        if (type_mro_meth == NULL) {
  Branch (352:13): [True: 0, False: 34.8k]
353
0
            Py_DECREF(mro_meth);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
354
0
            goto clear;
355
0
        }
356
34.8k
        int custom_mro = (mro_meth != type_mro_meth);
357
34.8k
        Py_DECREF(mro_meth);
Line
Count
Source
548
34.8k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
34.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
34.8k
#  define _Py_CAST(type, expr) ((type)(expr))
358
34.8k
        Py_DECREF(type_mro_meth);
Line
Count
Source
548
34.8k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
34.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
34.8k
#  define _Py_CAST(type, expr) ((type)(expr))
359
34.8k
        if (custom_mro) {
  Branch (359:13): [True: 86, False: 34.7k]
360
86
            goto clear;
361
86
        }
362
34.8k
    }
363
229k
    n = PyTuple_GET_SIZE(bases);
Line
Count
Source
26
229k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
229k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
229k
#  define _Py_CAST(type, expr) ((type)(expr))
364
780k
    for (i = 0; i < n; i++) {
  Branch (364:17): [True: 550k, False: 229k]
365
550k
        PyObject *b = PyTuple_GET_ITEM(bases, i);
Line
Count
Source
28
550k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
550k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
550k
#  define _Py_CAST(type, expr) ((type)(expr))
366
550k
        PyTypeObject *cls = _PyType_CAST(b);
Line
Count
Source
792
550k
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
550k
#  define _Py_CAST(type, expr) ((type)(expr))
367
368
550k
        if (!PyType_IsSubtype(type, cls)) {
  Branch (368:13): [True: 1, False: 550k]
369
1
            goto clear;
370
1
        }
371
550k
    }
372
229k
    return;
373
229k
 clear:
374
87
    type->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
Line
Count
Source
407
87
#define Py_TPFLAGS_VALID_VERSION_TAG  (1UL << 19)
375
87
    type->tp_version_tag = 0; /* 0 is not a valid version tag */
376
87
}
377
378
static int
379
assign_version_tag(struct type_cache *cache, PyTypeObject *type)
380
5.99M
{
381
    /* Ensure that the tp_version_tag is valid and set
382
       Py_TPFLAGS_VALID_VERSION_TAG.  To respect the invariant, this
383
       must first be done on all super classes.  Return 0 if this
384
       cannot be done, 1 if Py_TPFLAGS_VALID_VERSION_TAG.
385
    */
386
5.99M
    if (_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) {
Line
Count
Source
407
5.99M
#define Py_TPFLAGS_VALID_VERSION_TAG  (1UL << 19)
  Branch (386:9): [True: 5.80M, False: 195k]
387
5.80M
        return 1;
388
5.80M
    }
389
195k
    if (!_PyType_HasFeature(type, Py_TPFLAGS_READY)) {
Line
Count
Source
388
195k
#define Py_TPFLAGS_READY (1UL << 12)
  Branch (389:9): [True: 0, False: 195k]
390
0
        return 0;
391
0
    }
392
393
195k
    if (next_version_tag == 0) {
  Branch (393:9): [True: 0, False: 195k]
394
        /* We have run out of version numbers */
395
0
        return 0;
396
0
    }
397
195k
    type->tp_version_tag = next_version_tag++;
398
195k
    assert (type->tp_version_tag != 0);
399
400
195k
    PyObject *bases = type->tp_bases;
401
195k
    Py_ssize_t n = PyTuple_GET_SIZE(bases);
Line
Count
Source
26
195k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
195k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
195k
#  define _Py_CAST(type, expr) ((type)(expr))
402
412k
    for (Py_ssize_t i = 0; i < n; i++) {
  Branch (402:28): [True: 217k, False: 195k]
403
217k
        PyObject *b = PyTuple_GET_ITEM(bases, i);
Line
Count
Source
28
217k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
217k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
217k
#  define _Py_CAST(type, expr) ((type)(expr))
404
217k
        if (!assign_version_tag(cache, _PyType_CAST(b)))
Line
Count
Source
792
217k
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
217k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (404:13): [True: 0, False: 217k]
405
0
            return 0;
406
217k
    }
407
195k
    type->tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG;
Line
Count
Source
407
195k
#define Py_TPFLAGS_VALID_VERSION_TAG  (1UL << 19)
408
195k
    return 1;
409
195k
}
410
411
412
static PyMemberDef type_members[] = {
413
    {"__basicsize__", T_PYSSIZET, offsetof(PyTypeObject,tp_basicsize),READONLY},
414
    {"__itemsize__", T_PYSSIZET, offsetof(PyTypeObject, tp_itemsize), READONLY},
415
    {"__flags__", T_ULONG, offsetof(PyTypeObject, tp_flags), READONLY},
416
    {"__weakrefoffset__", T_PYSSIZET,
417
     offsetof(PyTypeObject, tp_weaklistoffset), READONLY},
418
    {"__base__", T_OBJECT, offsetof(PyTypeObject, tp_base), READONLY},
419
    {"__dictoffset__", T_PYSSIZET,
420
     offsetof(PyTypeObject, tp_dictoffset), READONLY},
421
    {"__mro__", T_OBJECT, offsetof(PyTypeObject, tp_mro), READONLY},
422
    {0}
423
};
424
425
static int
426
check_set_special_type_attr(PyTypeObject *type, PyObject *value, const char *name)
427
2.19k
{
428
2.19k
    if (_PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE)) {
Line
Count
Source
372
2.19k
#define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
  Branch (428:9): [True: 2, False: 2.19k]
429
2
        PyErr_Format(PyExc_TypeError,
430
2
                     "cannot set '%s' attribute of immutable type '%s'",
431
2
                     name, type->tp_name);
432
2
        return 0;
433
2
    }
434
2.19k
    if (!value) {
  Branch (434:9): [True: 3, False: 2.19k]
435
3
        PyErr_Format(PyExc_TypeError,
436
3
                     "cannot delete '%s' attribute of immutable type '%s'",
437
3
                     name, type->tp_name);
438
3
        return 0;
439
3
    }
440
441
2.19k
    if (PySys_Audit("object.__setattr__", "OsO",
  Branch (441:9): [True: 0, False: 2.19k]
442
2.19k
                    type, name, value) < 0) {
443
0
        return 0;
444
0
    }
445
446
2.19k
    return 1;
447
2.19k
}
448
449
const char *
450
_PyType_Name(PyTypeObject *type)
451
569k
{
452
569k
    assert(type->tp_name != NULL);
453
569k
    const char *s = strrchr(type->tp_name, '.');
454
569k
    if (s == NULL) {
  Branch (454:9): [True: 535k, False: 34.3k]
455
535k
        s = type->tp_name;
456
535k
    }
457
34.3k
    else {
458
34.3k
        s++;
459
34.3k
    }
460
569k
    return s;
461
569k
}
462
463
static PyObject *
464
type_name(PyTypeObject *type, void *context)
465
1.07M
{
466
1.07M
    if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
Line
Count
Source
375
1.07M
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (466:9): [True: 543k, False: 533k]
467
543k
        PyHeapTypeObject* et = (PyHeapTypeObject*)type;
468
469
543k
        Py_INCREF(et->ht_name);
Line
Count
Source
512
543k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
543k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
543k
#  define _Py_CAST(type, expr) ((type)(expr))
470
543k
        return et->ht_name;
471
543k
    }
472
533k
    else {
473
533k
        return PyUnicode_FromString(_PyType_Name(type));
474
533k
    }
475
1.07M
}
476
477
static PyObject *
478
type_qualname(PyTypeObject *type, void *context)
479
270k
{
480
270k
    if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
Line
Count
Source
375
270k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (480:9): [True: 245k, False: 24.7k]
481
245k
        PyHeapTypeObject* et = (PyHeapTypeObject*)type;
482
245k
        Py_INCREF(et->ht_qualname);
Line
Count
Source
512
245k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
245k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
245k
#  define _Py_CAST(type, expr) ((type)(expr))
483
245k
        return et->ht_qualname;
484
245k
    }
485
24.7k
    else {
486
24.7k
        return PyUnicode_FromString(_PyType_Name(type));
487
24.7k
    }
488
270k
}
489
490
static int
491
type_set_name(PyTypeObject *type, PyObject *value, void *context)
492
263
{
493
263
    const char *tp_name;
494
263
    Py_ssize_t name_size;
495
496
263
    if (!check_set_special_type_attr(type, value, "__name__"))
  Branch (496:9): [True: 0, False: 263]
497
0
        return -1;
498
263
    if (!PyUnicode_Check(value)) {
Line
Count
Source
115
263
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
263
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (498:9): [True: 1, False: 262]
499
1
        PyErr_Format(PyExc_TypeError,
500
1
                     "can only assign string to %s.__name__, not '%s'",
501
1
                     type->tp_name, Py_TYPE(value)->tp_name);
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
502
1
        return -1;
503
1
    }
504
505
262
    tp_name = PyUnicode_AsUTF8AndSize(value, &name_size);
506
262
    if (tp_name == NULL)
  Branch (506:9): [True: 1, False: 261]
507
1
        return -1;
508
261
    if (strlen(tp_name) != (size_t)name_size) {
  Branch (508:9): [True: 1, False: 260]
509
1
        PyErr_SetString(PyExc_ValueError,
510
1
                        "type name must not contain null characters");
511
1
        return -1;
512
1
    }
513
514
260
    type->tp_name = tp_name;
515
260
    Py_INCREF(value);
Line
Count
Source
512
260
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
260
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
260
#  define _Py_CAST(type, expr) ((type)(expr))
516
260
    Py_SETREF(((PyHeapTypeObject*)type)->ht_name, value);
Line
Count
Source
332
260
    do {                                        \
333
260
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
260
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
260
#  define _Py_CAST(type, expr) ((type)(expr))
334
260
        (op) = (op2);                           \
335
260
        Py_DECREF(_py_tmp);                     \
Line
Count
Source
548
260
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
260
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
260
#  define _Py_CAST(type, expr) ((type)(expr))
336
260
    } while (0)
  Branch (336:14): [Folded - Ignored]
517
518
260
    return 0;
519
261
}
520
521
static int
522
type_set_qualname(PyTypeObject *type, PyObject *value, void *context)
523
292
{
524
292
    PyHeapTypeObject* et;
525
526
292
    if (!check_set_special_type_attr(type, value, "__qualname__"))
  Branch (526:9): [True: 2, False: 290]
527
2
        return -1;
528
290
    if (!PyUnicode_Check(value)) {
Line
Count
Source
115
290
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
290
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (528:9): [True: 1, False: 289]
529
1
        PyErr_Format(PyExc_TypeError,
530
1
                     "can only assign string to %s.__qualname__, not '%s'",
531
1
                     type->tp_name, Py_TYPE(value)->tp_name);
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
532
1
        return -1;
533
1
    }
534
535
289
    et = (PyHeapTypeObject*)type;
536
289
    Py_INCREF(value);
Line
Count
Source
512
289
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
289
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
289
#  define _Py_CAST(type, expr) ((type)(expr))
537
289
    Py_SETREF(et->ht_qualname, value);
Line
Count
Source
332
289
    do {                                        \
333
289
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
289
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
289
#  define _Py_CAST(type, expr) ((type)(expr))
334
289
        (op) = (op2);                           \
335
289
        Py_DECREF(_py_tmp);                     \
Line
Count
Source
548
289
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
289
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
289
#  define _Py_CAST(type, expr) ((type)(expr))
336
289
    } while (0)
  Branch (336:14): [Folded - Ignored]
538
289
    return 0;
539
290
}
540
541
static PyObject *
542
type_module(PyTypeObject *type, void *context)
543
287k
{
544
287k
    PyObject *mod;
545
546
287k
    if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
Line
Count
Source
375
287k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (546:9): [True: 259k, False: 28.4k]
547
259k
        mod = PyDict_GetItemWithError(type->tp_dict, &_Py_ID(__module__));
Line
Count
Source
374
259k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
259k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
259k
    _PyRuntime.global_objects.NAME
548
259k
        if (mod == NULL) {
  Branch (548:13): [True: 0, False: 259k]
549
0
            if (!PyErr_Occurred()) {
  Branch (549:17): [True: 0, False: 0]
550
0
                PyErr_Format(PyExc_AttributeError, "__module__");
551
0
            }
552
0
            return NULL;
553
0
        }
554
259k
        Py_INCREF(mod);
Line
Count
Source
512
259k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
259k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
259k
#  define _Py_CAST(type, expr) ((type)(expr))
555
259k
    }
556
28.4k
    else {
557
28.4k
        const char *s = strrchr(type->tp_name, '.');
558
28.4k
        if (s != NULL) {
  Branch (558:13): [True: 14.0k, False: 14.3k]
559
14.0k
            mod = PyUnicode_FromStringAndSize(
560
14.0k
                type->tp_name, (Py_ssize_t)(s - type->tp_name));
561
14.0k
            if (mod != NULL)
  Branch (561:17): [True: 14.0k, False: 0]
562
14.0k
                PyUnicode_InternInPlace(&mod);
563
14.0k
        }
564
14.3k
        else {
565
14.3k
            mod = &_Py_ID(builtins);
Line
Count
Source
374
14.3k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
14.3k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
14.3k
    _PyRuntime.global_objects.NAME
566
14.3k
            Py_INCREF(mod);
Line
Count
Source
512
14.3k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
14.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14.3k
#  define _Py_CAST(type, expr) ((type)(expr))
567
14.3k
        }
568
28.4k
    }
569
287k
    return mod;
570
287k
}
571
572
static int
573
type_set_module(PyTypeObject *type, PyObject *value, void *context)
574
1.12k
{
575
1.12k
    if (!check_set_special_type_attr(type, value, "__module__"))
  Branch (575:9): [True: 0, False: 1.12k]
576
0
        return -1;
577
578
1.12k
    PyType_Modified(type);
579
580
1.12k
    return PyDict_SetItem(type->tp_dict, &_Py_ID(__module__), value);
Line
Count
Source
374
1.12k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1.12k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1.12k
    _PyRuntime.global_objects.NAME
581
1.12k
}
582
583
static PyObject *
584
type_abstractmethods(PyTypeObject *type, void *context)
585
15.8k
{
586
15.8k
    PyObject *mod = NULL;
587
    /* type itself has an __abstractmethods__ descriptor (this). Don't return
588
       that. */
589
15.8k
    if (type != &PyType_Type)
  Branch (589:9): [True: 15.8k, False: 6]
590
15.8k
        mod = PyDict_GetItemWithError(type->tp_dict,
591
15.8k
                                      &_Py_ID(__abstractmethods__));
Line
Count
Source
374
15.8k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
15.8k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
15.8k
    _PyRuntime.global_objects.NAME
592
15.8k
    if (!mod) {
  Branch (592:9): [True: 5.08k, False: 10.7k]
593
5.08k
        if (!PyErr_Occurred()) {
  Branch (593:13): [True: 5.08k, False: 0]
594
5.08k
            PyErr_SetObject(PyExc_AttributeError, &_Py_ID(__abstractmethods__));
Line
Count
Source
374
5.08k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
5.08k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
5.08k
    _PyRuntime.global_objects.NAME
595
5.08k
        }
596
5.08k
        return NULL;
597
5.08k
    }
598
10.7k
    Py_INCREF(mod);
Line
Count
Source
512
10.7k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
10.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10.7k
#  define _Py_CAST(type, expr) ((type)(expr))
599
10.7k
    return mod;
600
15.8k
}
601
602
static int
603
type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context)
604
11.1k
{
605
    /* __abstractmethods__ should only be set once on a type, in
606
       abc.ABCMeta.__new__, so this function doesn't do anything
607
       special to update subclasses.
608
    */
609
11.1k
    int abstract, res;
610
11.1k
    if (value != NULL) {
  Branch (610:9): [True: 11.1k, False: 1]
611
11.1k
        abstract = PyObject_IsTrue(value);
612
11.1k
        if (abstract < 0)
  Branch (612:13): [True: 0, False: 11.1k]
613
0
            return -1;
614
11.1k
        res = PyDict_SetItem(type->tp_dict, &_Py_ID(__abstractmethods__), value);
Line
Count
Source
374
11.1k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
11.1k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
11.1k
    _PyRuntime.global_objects.NAME
615
11.1k
    }
616
1
    else {
617
1
        abstract = 0;
618
1
        res = PyDict_DelItem(type->tp_dict, &_Py_ID(__abstractmethods__));
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
619
1
        if (res && PyErr_ExceptionMatches(PyExc_KeyError)) {
  Branch (619:13): [True: 1, False: 0]
  Branch (619:20): [True: 1, False: 0]
620
1
            PyErr_SetObject(PyExc_AttributeError, &_Py_ID(__abstractmethods__));
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
621
1
            return -1;
622
1
        }
623
1
    }
624
11.1k
    if (res == 0) {
  Branch (624:9): [True: 11.1k, False: 0]
625
11.1k
        PyType_Modified(type);
626
11.1k
        if (abstract)
  Branch (626:13): [True: 6.47k, False: 4.63k]
627
6.47k
            type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT;
Line
Count
Source
410
6.47k
#define Py_TPFLAGS_IS_ABSTRACT (1UL << 20)
628
4.63k
        else
629
4.63k
            type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT;
Line
Count
Source
410
4.63k
#define Py_TPFLAGS_IS_ABSTRACT (1UL << 20)
630
11.1k
    }
631
11.1k
    return res;
632
11.1k
}
633
634
static PyObject *
635
type_get_bases(PyTypeObject *type, void *context)
636
75.9k
{
637
75.9k
    Py_INCREF(type->tp_bases);
Line
Count
Source
512
75.9k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
75.9k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
75.9k
#  define _Py_CAST(type, expr) ((type)(expr))
638
75.9k
    return type->tp_bases;
639
75.9k
}
640
641
static PyTypeObject *best_base(PyObject *);
642
static int mro_internal(PyTypeObject *, PyObject **);
643
static int type_is_subtype_base_chain(PyTypeObject *, PyTypeObject *);
644
static int compatible_for_assignment(PyTypeObject *, PyTypeObject *, const char *);
645
static int add_subclass(PyTypeObject*, PyTypeObject*);
646
static int add_all_subclasses(PyTypeObject *type, PyObject *bases);
647
static void remove_subclass(PyTypeObject *, PyTypeObject *);
648
static void remove_all_subclasses(PyTypeObject *type, PyObject *bases);
649
static void update_all_slots(PyTypeObject *);
650
651
typedef int (*update_callback)(PyTypeObject *, void *);
652
static int update_subclasses(PyTypeObject *type, PyObject *attr_name,
653
                             update_callback callback, void *data);
654
static int recurse_down_subclasses(PyTypeObject *type, PyObject *name,
655
                                   update_callback callback, void *data);
656
657
static int
658
mro_hierarchy(PyTypeObject *type, PyObject *temp)
659
163
{
660
163
    PyObject *old_mro;
661
163
    int res = mro_internal(type, &old_mro);
662
163
    if (res <= 0) {
  Branch (662:9): [True: 21, False: 142]
663
        /* error / reentrance */
664
21
        return res;
665
21
    }
666
142
    PyObject *new_mro = type->tp_mro;
667
668
142
    PyObject *tuple;
669
142
    if (old_mro != NULL) {
  Branch (669:9): [True: 141, False: 1]
670
141
        tuple = PyTuple_Pack(3, type, new_mro, old_mro);
671
141
    }
672
1
    else {
673
1
        tuple = PyTuple_Pack(2, type, new_mro);
674
1
    }
675
676
142
    if (tuple != NULL) {
  Branch (676:9): [True: 142, False: 0]
677
142
        res = PyList_Append(temp, tuple);
678
142
    }
679
0
    else {
680
0
        res = -1;
681
0
    }
682
142
    Py_XDECREF(tuple);
Line
Count
Source
613
142
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
142
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
142
#  define _Py_CAST(type, expr) ((type)(expr))
683
684
142
    if (res < 0) {
  Branch (684:9): [True: 0, False: 142]
685
0
        type->tp_mro = old_mro;
686
0
        Py_DECREF(new_mro);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
687
0
        return -1;
688
0
    }
689
142
    Py_XDECREF(old_mro);
Line
Count
Source
613
142
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
142
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
142
#  define _Py_CAST(type, expr) ((type)(expr))
690
691
    // Avoid creating an empty list if there is no subclass
692
142
    if (type->tp_subclasses != NULL) {
  Branch (692:9): [True: 40, False: 102]
693
        /* Obtain a copy of subclasses list to iterate over.
694
695
           Otherwise type->tp_subclasses might be altered
696
           in the middle of the loop, for example, through a custom mro(),
697
           by invoking type_set_bases on some subclass of the type
698
           which in turn calls remove_subclass/add_subclass on this type.
699
700
           Finally, this makes things simple avoiding the need to deal
701
           with dictionary iterators and weak references.
702
        */
703
40
        PyObject *subclasses = _PyType_GetSubclasses(type);
704
40
        if (subclasses == NULL) {
  Branch (704:13): [True: 0, False: 40]
705
0
            return -1;
706
0
        }
707
708
40
        Py_ssize_t n = PyList_GET_SIZE(subclasses);
Line
Count
Source
37
40
#define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
40
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
40
#  define _Py_CAST(type, expr) ((type)(expr))
709
148
        for (Py_ssize_t i = 0; i < n; i++) {
  Branch (709:32): [True: 110, False: 38]
710
110
            PyTypeObject *subclass = _PyType_CAST(PyList_GET_ITEM(subclasses, i));
Line
Count
Source
792
110
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
110
#  define _Py_CAST(type, expr) ((type)(expr))
711
110
            res = mro_hierarchy(subclass, temp);
712
110
            if (res < 0) {
  Branch (712:17): [True: 2, False: 108]
713
2
                break;
714
2
            }
715
110
        }
716
40
        Py_DECREF(subclasses);
Line
Count
Source
548
40
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
40
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
40
#  define _Py_CAST(type, expr) ((type)(expr))
717
40
    }
718
719
142
    return res;
720
142
}
721
722
static int
723
type_set_bases(PyTypeObject *type, PyObject *new_bases, void *context)
724
65
{
725
    // Check arguments
726
65
    if (!check_set_special_type_attr(type, new_bases, "__bases__")) {
  Branch (726:9): [True: 1, False: 64]
727
1
        return -1;
728
1
    }
729
64
    assert(new_bases != NULL);
730
731
64
    if (!PyTuple_Check(new_bases)) {
Line
Count
Source
27
64
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
Line
Count
Source
782
64
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (731:9): [True: 0, False: 64]
732
0
        PyErr_Format(PyExc_TypeError,
733
0
             "can only assign tuple to %s.__bases__, not %s",
734
0
                 type->tp_name, Py_TYPE(new_bases)->tp_name);
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
735
0
        return -1;
736
0
    }
737
64
    if (PyTuple_GET_SIZE(new_bases) == 0) {
Line
Count
Source
26
64
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
64
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
64
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (737:9): [True: 1, False: 63]
738
1
        PyErr_Format(PyExc_TypeError,
739
1
             "can only assign non-empty tuple to %s.__bases__, not ()",
740
1
                 type->tp_name);
741
1
        return -1;
742
1
    }
743
63
    Py_ssize_t n = PyTuple_GET_SIZE(new_bases);
Line
Count
Source
26
63
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
63
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
63
#  define _Py_CAST(type, expr) ((type)(expr))
744
137
    for (Py_ssize_t i = 0; i < n; i++) {
  Branch (744:28): [True: 77, False: 60]
745
77
        PyObject *ob = PyTuple_GET_ITEM(new_bases, i);
Line
Count
Source
28
77
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
77
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
77
#  define _Py_CAST(type, expr) ((type)(expr))
746
77
        if (!PyType_Check(ob)) {
Line
Count
Source
788
77
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
77
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
77
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (746:13): [True: 0, False: 77]
747
0
            PyErr_Format(PyExc_TypeError,
748
0
                         "%s.__bases__ must be tuple of classes, not '%s'",
749
0
                         type->tp_name, Py_TYPE(ob)->tp_name);
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
750
0
            return -1;
751
0
        }
752
77
        PyTypeObject *base = (PyTypeObject*)ob;
753
754
77
        if (PyType_IsSubtype(base, type) ||
  Branch (754:13): [True: 2, False: 75]
755
            /* In case of reentering here again through a custom mro()
756
               the above check is not enough since it relies on
757
               base->tp_mro which would gonna be updated inside
758
               mro_internal only upon returning from the mro().
759
760
               However, base->tp_base has already been assigned (see
761
               below), which in turn may cause an inheritance cycle
762
               through tp_base chain.  And this is definitely
763
               not what you want to ever happen.  */
764
77
            (base->tp_mro != NULL && type_is_subtype_base_chain(base, type)))
  Branch (764:14): [True: 75, False: 0]
  Branch (764:38): [True: 1, False: 74]
765
3
        {
766
3
            PyErr_SetString(PyExc_TypeError,
767
3
                            "a __bases__ item causes an inheritance cycle");
768
3
            return -1;
769
3
        }
770
77
    }
771
772
    // Compute the new MRO and the new base class
773
60
    PyTypeObject *new_base = best_base(new_bases);
774
60
    if (new_base == NULL)
  Branch (774:9): [True: 5, False: 55]
775
5
        return -1;
776
777
55
    if (!compatible_for_assignment(type->tp_base, new_base, "__bases__")) {
  Branch (777:9): [True: 2, False: 53]
778
2
        return -1;
779
2
    }
780
781
53
    PyObject *old_bases = type->tp_bases;
782
53
    assert(old_bases != NULL);
783
53
    PyTypeObject *old_base = type->tp_base;
784
785
53
    type->tp_bases = Py_NewRef(new_bases);
Line
Count
Source
639
53
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
53
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
53
#  define _Py_CAST(type, expr) ((type)(expr))
786
53
    type->tp_base = (PyTypeObject *)Py_NewRef(new_base);
Line
Count
Source
639
53
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
53
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
53
#  define _Py_CAST(type, expr) ((type)(expr))
787
788
53
    PyObject *temp = PyList_New(0);
789
53
    if (temp == NULL) {
  Branch (789:9): [True: 0, False: 53]
790
0
        goto bail;
791
0
    }
792
53
    if (mro_hierarchy(type, temp) < 0) {
  Branch (792:9): [True: 7, False: 46]
793
7
        goto undo;
794
7
    }
795
46
    Py_DECREF(temp);
Line
Count
Source
548
46
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
46
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
46
#  define _Py_CAST(type, expr) ((type)(expr))
796
797
    /* Take no action in case if type->tp_bases has been replaced
798
       through reentrance.  */
799
46
    int res;
800
46
    if (type->tp_bases == new_bases) {
  Branch (800:9): [True: 45, False: 1]
801
        /* any base that was in __bases__ but now isn't, we
802
           need to remove |type| from its tp_subclasses.
803
           conversely, any class now in __bases__ that wasn't
804
           needs to have |type| added to its subclasses. */
805
806
        /* for now, sod that: just remove from all old_bases,
807
           add to all new_bases */
808
45
        remove_all_subclasses(type, old_bases);
809
45
        res = add_all_subclasses(type, new_bases);
810
45
        update_all_slots(type);
811
45
    }
812
1
    else {
813
1
        res = 0;
814
1
    }
815
816
46
    Py_DECREF(old_bases);
Line
Count
Source
548
46
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
46
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
46
#  define _Py_CAST(type, expr) ((type)(expr))
817
46
    Py_DECREF(old_base);
Line
Count
Source
548
46
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
46
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
46
#  define _Py_CAST(type, expr) ((type)(expr))
818
819
46
    assert(_PyType_CheckConsistency(type));
820
46
    return res;
821
822
7
  undo:
823
7
    n = PyList_GET_SIZE(temp);
Line
Count
Source
37
7
#define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
7
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7
#  define _Py_CAST(type, expr) ((type)(expr))
824
10
    for (Py_ssize_t i = n - 1; i >= 0; i--) {
  Branch (824:32): [True: 3, False: 7]
825
3
        PyTypeObject *cls;
826
3
        PyObject *new_mro, *old_mro = NULL;
827
828
3
        PyArg_UnpackTuple(PyList_GET_ITEM(temp, i),
Line
Count
Source
39
3
#define PyList_GET_ITEM(op, index) (_PyList_CAST(op)->ob_item[(index)])
Line
Count
Source
29
3
    (assert(PyList_Check(op)), _Py_CAST(PyListObject*, (op)))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
829
3
                          "", 2, 3, &cls, &new_mro, &old_mro);
830
        /* Do not rollback if cls has a newer version of MRO.  */
831
3
        if (cls->tp_mro == new_mro) {
  Branch (831:13): [True: 3, False: 0]
832
3
            Py_XINCREF(old_mro);
Line
Count
Source
603
3
#  define Py_XINCREF(op) Py_XINCREF(_PyObject_CAST(op))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
833
3
            cls->tp_mro = old_mro;
834
3
            Py_DECREF(new_mro);
Line
Count
Source
548
3
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
835
3
        }
836
3
    }
837
7
    Py_DECREF(temp);
Line
Count
Source
548
7
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
7
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7
#  define _Py_CAST(type, expr) ((type)(expr))
838
839
7
  bail:
840
7
    if (type->tp_bases == new_bases) {
  Branch (840:9): [True: 6, False: 1]
841
6
        assert(type->tp_base == new_base);
842
843
6
        type->tp_bases = old_bases;
844
6
        type->tp_base = old_base;
845
846
6
        Py_DECREF(new_bases);
Line
Count
Source
548
6
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
847
6
        Py_DECREF(new_base);
Line
Count
Source
548
6
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
848
6
    }
849
1
    else {
850
1
        Py_DECREF(old_bases);
Line
Count
Source
548
1
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
851
1
        Py_DECREF(old_base);
Line
Count
Source
548
1
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
852
1
    }
853
854
7
    assert(_PyType_CheckConsistency(type));
855
7
    return -1;
856
7
}
857
858
static PyObject *
859
type_dict(PyTypeObject *type, void *context)
860
330k
{
861
330k
    if (type->tp_dict == NULL) {
  Branch (861:9): [True: 0, False: 330k]
862
0
        Py_RETURN_NONE;
Line
Count
Source
661
0
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
0
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
863
0
    }
864
330k
    return PyDictProxy_New(type->tp_dict);
865
330k
}
866
867
static PyObject *
868
type_get_doc(PyTypeObject *type, void *context)
869
16.3k
{
870
16.3k
    PyObject *result;
871
16.3k
    if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) {
Line
Count
Source
375
16.3k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (871:9): [True: 4.44k, False: 11.9k]
  Branch (871:52): [True: 3.92k, False: 521]
872
3.92k
        return _PyType_GetDocFromInternalDoc(type->tp_name, type->tp_doc);
873
3.92k
    }
874
12.4k
    result = PyDict_GetItemWithError(type->tp_dict, &_Py_ID(__doc__));
Line
Count
Source
374
12.4k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
12.4k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
12.4k
    _PyRuntime.global_objects.NAME
875
12.4k
    if (result == NULL) {
  Branch (875:9): [True: 0, False: 12.4k]
876
0
        if (!PyErr_Occurred()) {
  Branch (876:13): [True: 0, False: 0]
877
0
            result = Py_None;
Line
Count
Source
654
0
#define Py_None (&_Py_NoneStruct)
878
0
            Py_INCREF(result);
Line
Count
Source
512
0
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
879
0
        }
880
0
    }
881
12.4k
    else if (Py_TYPE(result)->tp_descr_get) {
Line
Count
Source
138
12.4k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
12.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12.4k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (881:14): [True: 525, False: 11.9k]
882
525
        result = Py_TYPE(result)->tp_descr_get(result, NULL,
Line
Count
Source
138
525
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
525
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
525
#  define _Py_CAST(type, expr) ((type)(expr))
883
525
                                               (PyObject *)type);
884
525
    }
885
11.9k
    else {
886
11.9k
        Py_INCREF(result);
Line
Count
Source
512
11.9k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
11.9k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11.9k
#  define _Py_CAST(type, expr) ((type)(expr))
887
11.9k
    }
888
12.4k
    return result;
889
16.3k
}
890
891
static PyObject *
892
type_get_text_signature(PyTypeObject *type, void *context)
893
290
{
894
290
    return _PyType_GetTextSignatureFromInternalDoc(type->tp_name, type->tp_doc);
895
290
}
896
897
static int
898
type_set_doc(PyTypeObject *type, PyObject *value, void *context)
899
452
{
900
452
    if (!check_set_special_type_attr(type, value, "__doc__"))
  Branch (900:9): [True: 2, False: 450]
901
2
        return -1;
902
450
    PyType_Modified(type);
903
450
    return PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), value);
Line
Count
Source
374
450
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
450
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
450
    _PyRuntime.global_objects.NAME
904
452
}
905
906
static PyObject *
907
type_get_annotations(PyTypeObject *type, void *context)
908
2.71k
{
909
2.71k
    if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
Line
Count
Source
375
2.71k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (909:9): [True: 2.04k, False: 668]
910
2.04k
        PyErr_Format(PyExc_AttributeError, "type object '%s' has no attribute '__annotations__'", type->tp_name);
911
2.04k
        return NULL;
912
2.04k
    }
913
914
668
    PyObject *annotations;
915
    /* there's no _PyDict_GetItemId without WithError, so let's LBYL. */
916
668
    if (PyDict_Contains(type->tp_dict, &_Py_ID(__annotations__))) {
Line
Count
Source
374
668
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
668
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
668
    _PyRuntime.global_objects.NAME
  Branch (916:9): [True: 326, False: 342]
917
326
        annotations = PyDict_GetItemWithError(
918
326
                type->tp_dict, &_Py_ID(__annotations__));
Line
Count
Source
374
326
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
326
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
326
    _PyRuntime.global_objects.NAME
919
        /*
920
        ** PyDict_GetItemWithError could still fail,
921
        ** for instance with a well-timed Ctrl-C or a MemoryError.
922
        ** so let's be totally safe.
923
        */
924
326
        if (annotations) {
  Branch (924:13): [True: 326, False: 0]
925
326
            if (Py_TYPE(annotations)->tp_descr_get) {
Line
Count
Source
138
326
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
326
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
326
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (925:17): [True: 0, False: 326]
926
0
                annotations = Py_TYPE(annotations)->tp_descr_get(
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
927
0
                        annotations, NULL, (PyObject *)type);
928
326
            } else {
929
326
                Py_INCREF(annotations);
Line
Count
Source
512
326
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
326
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
326
#  define _Py_CAST(type, expr) ((type)(expr))
930
326
            }
931
326
        }
932
342
    } else {
933
342
        annotations = PyDict_New();
934
342
        if (annotations) {
  Branch (934:13): [True: 342, False: 0]
935
342
            int result = PyDict_SetItem(
936
342
                    type->tp_dict, &_Py_ID(__annotations__), annotations);
Line
Count
Source
374
342
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
342
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
342
    _PyRuntime.global_objects.NAME
937
342
            if (result) {
  Branch (937:17): [True: 0, False: 342]
938
0
                Py_CLEAR(annotations);
Line
Count
Source
587
0
    do {                                        \
588
0
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
589
0
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 0, False: 0]
590
0
            (op) = NULL;                        \
591
0
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
592
0
        }                                       \
593
0
    } while (0)
  Branch (593:14): [Folded - Ignored]
939
342
            } else {
940
342
                PyType_Modified(type);
941
342
            }
942
342
        }
943
342
    }
944
668
    return annotations;
945
2.71k
}
946
947
static int
948
type_set_annotations(PyTypeObject *type, PyObject *value, void *context)
949
96
{
950
96
    if (_PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE)) {
Line
Count
Source
372
96
#define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
  Branch (950:9): [True: 0, False: 96]
951
0
        PyErr_Format(PyExc_TypeError,
952
0
                     "cannot set '__annotations__' attribute of immutable type '%s'",
953
0
                     type->tp_name);
954
0
        return -1;
955
0
    }
956
957
96
    int result;
958
96
    if (value != NULL) {
  Branch (958:9): [True: 87, False: 9]
959
        /* set */
960
87
        result = PyDict_SetItem(type->tp_dict, &_Py_ID(__annotations__), value);
Line
Count
Source
374
87
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
87
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
87
    _PyRuntime.global_objects.NAME
961
87
    } else {
962
        /* delete */
963
9
        if (!PyDict_Contains(type->tp_dict, &_Py_ID(__annotations__))) {
Line
Count
Source
374
9
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
9
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
9
    _PyRuntime.global_objects.NAME
  Branch (963:13): [True: 1, False: 8]
964
1
            PyErr_Format(PyExc_AttributeError, "__annotations__");
965
1
            return -1;
966
1
        }
967
8
        result = PyDict_DelItem(type->tp_dict, &_Py_ID(__annotations__));
Line
Count
Source
374
8
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
8
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
8
    _PyRuntime.global_objects.NAME
968
8
    }
969
970
95
    if (result == 0) {
  Branch (970:9): [True: 95, False: 0]
971
95
        PyType_Modified(type);
972
95
    }
973
95
    return result;
974
96
}
975
976
977
/*[clinic input]
978
type.__instancecheck__ -> bool
979
980
    instance: object
981
    /
982
983
Check if an object is an instance.
984
[clinic start generated code]*/
985
986
static int
987
type___instancecheck___impl(PyTypeObject *self, PyObject *instance)
988
/*[clinic end generated code: output=08b6bf5f591c3618 input=cdbfeaee82c01a0f]*/
989
197k
{
990
197k
    return _PyObject_RealIsInstance(instance, (PyObject *)self);
991
197k
}
992
993
/*[clinic input]
994
type.__subclasscheck__ -> bool
995
996
    subclass: object
997
    /
998
999
Check if a class is a subclass.
1000
[clinic start generated code]*/
1001
1002
static int
1003
type___subclasscheck___impl(PyTypeObject *self, PyObject *subclass)
1004
/*[clinic end generated code: output=97a4e51694500941 input=071b2ca9e03355f4]*/
1005
99.9k
{
1006
99.9k
    return _PyObject_RealIsSubclass(subclass, (PyObject *)self);
1007
99.9k
}
1008
1009
1010
static PyGetSetDef type_getsets[] = {
1011
    {"__name__", (getter)type_name, (setter)type_set_name, NULL},
1012
    {"__qualname__", (getter)type_qualname, (setter)type_set_qualname, NULL},
1013
    {"__bases__", (getter)type_get_bases, (setter)type_set_bases, NULL},
1014
    {"__module__", (getter)type_module, (setter)type_set_module, NULL},
1015
    {"__abstractmethods__", (getter)type_abstractmethods,
1016
     (setter)type_set_abstractmethods, NULL},
1017
    {"__dict__",  (getter)type_dict,  NULL, NULL},
1018
    {"__doc__", (getter)type_get_doc, (setter)type_set_doc, NULL},
1019
    {"__text_signature__", (getter)type_get_text_signature, NULL, NULL},
1020
    {"__annotations__", (getter)type_get_annotations, (setter)type_set_annotations, NULL},
1021
    {0}
1022
};
1023
1024
static PyObject *
1025
type_repr(PyTypeObject *type)
1026
37.2k
{
1027
37.2k
    if (type->tp_name == NULL) {
  Branch (1027:9): [True: 0, False: 37.2k]
1028
        // type_repr() called before the type is fully initialized
1029
        // by PyType_Ready().
1030
0
        return PyUnicode_FromFormat("<class at %p>", type);
1031
0
    }
1032
1033
37.2k
    PyObject *mod, *name, *rtn;
1034
1035
37.2k
    mod = type_module(type, NULL);
1036
37.2k
    if (mod == NULL)
  Branch (1036:9): [True: 0, False: 37.2k]
1037
0
        PyErr_Clear();
1038
37.2k
    else if (!PyUnicode_Check(mod)) {
Line
Count
Source
115
37.2k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
37.2k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (1038:14): [True: 0, False: 37.2k]
1039
0
        Py_DECREF(mod);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
1040
0
        mod = NULL;
1041
0
    }
1042
37.2k
    name = type_qualname(type, NULL);
1043
37.2k
    if (name == NULL) {
  Branch (1043:9): [True: 0, False: 37.2k]
1044
0
        Py_XDECREF(mod);
Line
Count
Source
613
0
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
1045
0
        return NULL;
1046
0
    }
1047
1048
37.2k
    if (mod != NULL && !_PyUnicode_Equal(mod, &_Py_ID(builtins)))
Line
Count
Source
374
37.2k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
37.2k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
37.2k
    _PyRuntime.global_objects.NAME
  Branch (1048:9): [True: 37.2k, False: 0]
  Branch (1048:24): [True: 36.0k, False: 1.19k]
1049
36.0k
        rtn = PyUnicode_FromFormat("<class '%U.%U'>", mod, name);
1050
1.19k
    else
1051
1.19k
        rtn = PyUnicode_FromFormat("<class '%s'>", type->tp_name);
1052
1053
37.2k
    Py_XDECREF(mod);
Line
Count
Source
613
37.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
37.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
37.2k
#  define _Py_CAST(type, expr) ((type)(expr))
1054
37.2k
    Py_DECREF(name);
Line
Count
Source
548
37.2k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
37.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
37.2k
#  define _Py_CAST(type, expr) ((type)(expr))
1055
37.2k
    return rtn;
1056
37.2k
}
1057
1058
static PyObject *
1059
type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
1060
27.7M
{
1061
27.7M
    PyObject *obj;
1062
27.7M
    PyThreadState *tstate = _PyThreadState_GET();
1063
1064
#ifdef Py_DEBUG
1065
    /* type_call() must not be called with an exception set,
1066
       because it can clear it (directly or indirectly) and so the
1067
       caller loses its exception */
1068
    assert(!_PyErr_Occurred(tstate));
1069
#endif
1070
1071
    /* Special case: type(x) should return Py_TYPE(x) */
1072
    /* We only want type itself to accept the one-argument form (#27157) */
1073
27.7M
    if (type == &PyType_Type) {
  Branch (1073:9): [True: 69.6k, False: 27.6M]
1074
69.6k
        assert(args != NULL && PyTuple_Check(args));
1075
69.6k
        assert(kwds == NULL || PyDict_Check(kwds));
1076
69.6k
        Py_ssize_t nargs = PyTuple_GET_SIZE(args);
Line
Count
Source
26
69.6k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
69.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
69.6k
#  define _Py_CAST(type, expr) ((type)(expr))
1077
1078
69.6k
        if (nargs == 1 && (kwds == NULL || !PyDict_GET_SIZE(kwds))) {
Line
Count
Source
55
0
#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1078:13): [True: 0, False: 69.6k]
  Branch (1078:28): [True: 0, False: 0]
  Branch (1078:44): [True: 0, False: 0]
1079
0
            obj = (PyObject *) Py_TYPE(PyTuple_GET_ITEM(args, 0));
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
1080
0
            Py_INCREF(obj);
Line
Count
Source
512
0
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
1081
0
            return obj;
1082
0
        }
1083
1084
        /* SF bug 475327 -- if that didn't trigger, we need 3
1085
           arguments. But PyArg_ParseTuple in type_new may give
1086
           a msg saying type() needs exactly 3. */
1087
69.6k
        if (nargs != 3) {
  Branch (1087:13): [True: 8, False: 69.6k]
1088
8
            PyErr_SetString(PyExc_TypeError,
1089
8
                            "type() takes 1 or 3 arguments");
1090
8
            return NULL;
1091
8
        }
1092
69.6k
    }
1093
1094
27.7M
    if (type->tp_new == NULL) {
  Branch (1094:9): [True: 53, False: 27.7M]
1095
53
        _PyErr_Format(tstate, PyExc_TypeError,
1096
53
                      "cannot create '%s' instances", type->tp_name);
1097
53
        return NULL;
1098
53
    }
1099
1100
27.7M
    obj = type->tp_new(type, args, kwds);
1101
27.7M
    obj = _Py_CheckFunctionResult(tstate, (PyObject*)type, obj, NULL);
1102
27.7M
    if (obj == NULL)
  Branch (1102:9): [True: 49.5k, False: 27.6M]
1103
49.5k
        return NULL;
1104
1105
    /* If the returned object is not an instance of type,
1106
       it won't be initialized. */
1107
27.6M
    if (!PyObject_TypeCheck(obj, type))
Line
Count
Source
271
27.6M
#  define PyObject_TypeCheck(ob, type) PyObject_TypeCheck(_PyObject_CAST(ob), (type))
Line
Count
Source
109
27.6M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
27.6M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1107:9): [True: 167, False: 27.6M]
1108
167
        return obj;
1109
1110
27.6M
    type = Py_TYPE(obj);
Line
Count
Source
138
27.6M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
27.6M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
27.6M
#  define _Py_CAST(type, expr) ((type)(expr))
1111
27.6M
    if (type->tp_init != NULL) {
  Branch (1111:9): [True: 27.6M, False: 1]
1112
27.6M
        int res = type->tp_init(obj, args, kwds);
1113
27.6M
        if (res < 0) {
  Branch (1113:13): [True: 43.5k, False: 27.6M]
1114
43.5k
            assert(_PyErr_Occurred(tstate));
1115
43.5k
            Py_DECREF(obj);
Line
Count
Source
548
43.5k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
43.5k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
43.5k
#  define _Py_CAST(type, expr) ((type)(expr))
1116
43.5k
            obj = NULL;
1117
43.5k
        }
1118
27.6M
        else {
1119
27.6M
            assert(!_PyErr_Occurred(tstate));
1120
27.6M
        }
1121
27.6M
    }
1122
27.6M
    return obj;
1123
27.6M
}
1124
1125
PyObject *
1126
_PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems)
1127
31.3M
{
1128
31.3M
    PyObject *obj;
1129
31.3M
    const size_t size = _PyObject_VAR_SIZE(type, nitems+1);
Line
Count
Source
22
31.3M
    _Py_SIZE_ROUND_UP((typeobj)->tp_basicsize + \
Line
Count
Source
101
31.3M
#define _Py_SIZE_ROUND_UP(n, a) (((size_t)(n) + \
102
31.3M
        (size_t)((a) - 1)) & ~(size_t)((a) - 1))
23
31.3M
        (nitems)*(typeobj)->tp_itemsize,        \
24
31.3M
        SIZEOF_VOID_P)
1130
    /* note that we need to add one, for the sentinel */
1131
1132
31.3M
    const size_t presize = _PyType_PreHeaderSize(type);
1133
31.3M
    char *alloc = PyObject_Malloc(size + presize);
1134
31.3M
    if (alloc  == NULL) {
  Branch (1134:9): [True: 0, False: 31.3M]
1135
0
        return PyErr_NoMemory();
1136
0
    }
1137
31.3M
    obj = (PyObject *)(alloc + presize);
1138
31.3M
    if (presize) {
  Branch (1138:9): [True: 30.3M, False: 1.01M]
1139
30.3M
        ((PyObject **)alloc)[0] = NULL;
1140
30.3M
        ((PyObject **)alloc)[1] = NULL;
1141
30.3M
        _PyObject_GC_Link(obj);
1142
30.3M
    }
1143
31.3M
    memset(obj, '\0', size);
1144
1145
31.3M
    if (type->tp_itemsize == 0) {
  Branch (1145:9): [True: 30.1M, False: 1.16M]
1146
30.1M
        _PyObject_Init(obj, type);
1147
30.1M
    }
1148
1.16M
    else {
1149
1.16M
        _PyObject_InitVar((PyVarObject *)obj, type, nitems);
1150
1.16M
    }
1151
31.3M
    return obj;
1152
31.3M
}
1153
1154
PyObject *
1155
PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
1156
31.2M
{
1157
31.2M
    PyObject *obj = _PyType_AllocNoTrack(type, nitems);
1158
31.2M
    if (obj == NULL) {
  Branch (1158:9): [True: 0, False: 31.2M]
1159
0
        return NULL;
1160
0
    }
1161
1162
31.2M
    if (_PyType_IS_GC(type)) {
Line
Count
Source
222
31.2M
#define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
Line
Count
Source
394
31.2M
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (222:26): [True: 30.2M, False: 1.01M]
1163
30.2M
        _PyObject_GC_TRACK(obj);
Line
Count
Source
185
30.2M
        _PyObject_GC_TRACK(_PyObject_CAST(op))
Line
Count
Source
109
30.2M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
30.2M
#  define _Py_CAST(type, expr) ((type)(expr))
1164
30.2M
    }
1165
31.2M
    return obj;
1166
31.2M
}
1167
1168
PyObject *
1169
PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
1170
2.17M
{
1171
2.17M
    return type->tp_alloc(type, 0);
1172
2.17M
}
1173
1174
/* Helpers for subtyping */
1175
1176
static int
1177
traverse_slots(PyTypeObject *type, PyObject *self, visitproc visit, void *arg)
1178
20.2M
{
1179
20.2M
    Py_ssize_t i, n;
1180
20.2M
    PyMemberDef *mp;
1181
1182
20.2M
    n = Py_SIZE(type);
Line
Count
Source
147
20.2M
#  define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
Line
Count
Source
109
20.2M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.2M
#  define _Py_CAST(type, expr) ((type)(expr))
1183
20.2M
    mp = _PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
Line
Count
Source
279
20.2M
    ((PyMemberDef *)(((char *)(etype)) + Py_TYPE(etype)->tp_basicsize))
Line
Count
Source
138
20.2M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
20.2M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.2M
#  define _Py_CAST(type, expr) ((type)(expr))
1184
100M
    for (i = 0; i < n; i++, mp++) {
  Branch (1184:17): [True: 79.9M, False: 20.2M]
1185
79.9M
        if (mp->type == T_OBJECT_EX) {
Line
Count
Source
49
79.9M
#define T_OBJECT_EX 16  /* Like T_OBJECT, but raises AttributeError
  Branch (1185:13): [True: 79.9M, False: 0]
1186
79.9M
            char *addr = (char *)self + mp->offset;
1187
79.9M
            PyObject *obj = *(PyObject **)addr;
1188
79.9M
            if (obj != NULL) {
  Branch (1188:17): [True: 72.5M, False: 7.41M]
1189
72.5M
                int err = visit(obj, arg);
1190
72.5M
                if (err)
  Branch (1190:21): [True: 0, False: 72.5M]
1191
0
                    return err;
1192
72.5M
            }
1193
79.9M
        }
1194
79.9M
    }
1195
20.2M
    return 0;
1196
20.2M
}
1197
1198
static int
1199
subtype_traverse(PyObject *self, visitproc visit, void *arg)
1200
299M
{
1201
299M
    PyTypeObject *type, *base;
1202
299M
    traverseproc basetraverse;
1203
1204
    /* Find the nearest base with a different tp_traverse,
1205
       and traverse slots while we're at it */
1206
299M
    type = Py_TYPE(self);
Line
Count
Source
138
299M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
299M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
299M
#  define _Py_CAST(type, expr) ((type)(expr))
1207
299M
    base = type;
1208
764M
    while ((basetraverse = base->tp_traverse) == subtype_traverse) {
  Branch (1208:12): [True: 465M, False: 299M]
1209
465M
        if (Py_SIZE(base)) {
Line
Count
Source
147
465M
#  define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
Line
Count
Source
109
465M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
465M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (147:23): [True: 20.2M, False: 445M]
1210
20.2M
            int err = traverse_slots(base, self, visit, arg);
1211
20.2M
            if (err)
  Branch (1211:17): [True: 0, False: 20.2M]
1212
0
                return err;
1213
20.2M
        }
1214
465M
        base = base->tp_base;
1215
465M
        assert(base);
1216
465M
    }
1217
1218
299M
    if (type->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
Line
Count
Source
359
299M
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
  Branch (1218:9): [True: 236M, False: 62.6M]
1219
236M
        assert(type->tp_dictoffset);
1220
236M
        int err = _PyObject_VisitInstanceAttributes(self, visit, arg);
1221
236M
        if (err) {
  Branch (1221:13): [True: 0, False: 236M]
1222
0
            return err;
1223
0
        }
1224
236M
    }
1225
1226
299M
    if (type->tp_dictoffset != base->tp_dictoffset) {
  Branch (1226:9): [True: 256M, False: 42.3M]
1227
256M
        PyObject **dictptr = _PyObject_DictPointer(self);
1228
256M
        if (dictptr && *dictptr)
  Branch (1228:13): [True: 256M, False: 0]
  Branch (1228:24): [True: 37.7M, False: 219M]
1229
37.7M
            Py_VISIT(*dictptr);
Line
Count
Source
198
37.7M
    do {                                                                \
199
37.7M
        if (op) {                                                       \
  Branch (199:13): [True: 37.7M, False: 0]
200
37.7M
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
37.7M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
37.7M
#  define _Py_CAST(type, expr) ((type)(expr))
201
37.7M
            if (vret)                                                   \
  Branch (201:17): [True: 0, False: 37.7M]
202
37.7M
                return vret;                                            \
203
37.7M
        }                                                               \
204
37.7M
    } while (0)
  Branch (204:14): [Folded - Ignored]
1230
256M
    }
1231
1232
299M
    if (type->tp_flags & Py_TPFLAGS_HEAPTYPE
Line
Count
Source
375
598M
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (1232:9): [True: 299M, False: 0]
1233
299M
        && (!basetraverse || !(base->tp_flags & Py_TPFLAGS_HEAPTYPE))) {
Line
Count
Source
375
37.2M
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (1233:13): [True: 262M, False: 37.2M]
  Branch (1233:30): [True: 32.0M, False: 5.21M]
1234
        /* For a heaptype, the instances count as references
1235
           to the type.          Traverse the type so the collector
1236
           can find cycles involving this link.
1237
           Skip this visit if basetraverse belongs to a heap type: in that
1238
           case, basetraverse will visit the type when we call it later.
1239
           */
1240
294M
        Py_VISIT(type);
Line
Count
Source
198
294M
    do {                                                                \
199
294M
        if (op) {                                                       \
  Branch (199:13): [True: 294M, False: 0]
200
294M
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
294M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
294M
#  define _Py_CAST(type, expr) ((type)(expr))
201
294M
            if (vret)                                                   \
  Branch (201:17): [True: 0, False: 294M]
202
294M
                return vret;                                            \
203
294M
        }                                                               \
204
294M
    } while (0)
  Branch (204:14): [Folded - Ignored]
1241
294M
    }
1242
1243
299M
    if (basetraverse)
  Branch (1243:9): [True: 37.2M, False: 262M]
1244
37.2M
        return basetraverse(self, visit, arg);
1245
262M
    return 0;
1246
299M
}
1247
1248
static void
1249
clear_slots(PyTypeObject *type, PyObject *self)
1250
2.15M
{
1251
2.15M
    Py_ssize_t i, n;
1252
2.15M
    PyMemberDef *mp;
1253
1254
2.15M
    n = Py_SIZE(type);
Line
Count
Source
147
2.15M
#  define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
Line
Count
Source
109
2.15M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.15M
#  define _Py_CAST(type, expr) ((type)(expr))
1255
2.15M
    mp = _PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
Line
Count
Source
279
2.15M
    ((PyMemberDef *)(((char *)(etype)) + Py_TYPE(etype)->tp_basicsize))
Line
Count
Source
138
2.15M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.15M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.15M
#  define _Py_CAST(type, expr) ((type)(expr))
1256
8.83M
    for (i = 0; i < n; i++, mp++) {
  Branch (1256:17): [True: 6.67M, False: 2.15M]
1257
6.67M
        if (mp->type == T_OBJECT_EX && !(mp->flags & READONLY)) {
Line
Count
Source
49
13.3M
#define T_OBJECT_EX 16  /* Like T_OBJECT, but raises AttributeError
        if (mp->type == T_OBJECT_EX && !(mp->flags & READONLY)) {
Line
Count
Source
60
6.67M
#define READONLY            1
  Branch (1257:13): [True: 6.67M, False: 0]
  Branch (1257:40): [True: 6.67M, False: 0]
1258
6.67M
            char *addr = (char *)self + mp->offset;
1259
6.67M
            PyObject *obj = *(PyObject **)addr;
1260
6.67M
            if (obj != NULL) {
  Branch (1260:17): [True: 6.20M, False: 468k]
1261
6.20M
                *(PyObject **)addr = NULL;
1262
6.20M
                Py_DECREF(obj);
Line
Count
Source
548
6.20M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
6.20M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6.20M
#  define _Py_CAST(type, expr) ((type)(expr))
1263
6.20M
            }
1264
6.67M
        }
1265
6.67M
    }
1266
2.15M
}
1267
1268
static int
1269
subtype_clear(PyObject *self)
1270
1.85M
{
1271
1.85M
    PyTypeObject *type, *base;
1272
1.85M
    inquiry baseclear;
1273
1274
    /* Find the nearest base with a different tp_clear
1275
       and clear slots while we're at it */
1276
1.85M
    type = Py_TYPE(self);
Line
Count
Source
138
1.85M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1.85M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.85M
#  define _Py_CAST(type, expr) ((type)(expr))
1277
1.85M
    base = type;
1278
3.97M
    while ((baseclear = base->tp_clear) == subtype_clear) {
  Branch (1278:12): [True: 2.11M, False: 1.85M]
1279
2.11M
        if (Py_SIZE(base))
Line
Count
Source
147
2.11M
#  define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
Line
Count
Source
109
2.11M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.11M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (147:23): [True: 2.57k, False: 2.11M]
1280
2.57k
            clear_slots(base, self);
1281
2.11M
        base = base->tp_base;
1282
2.11M
        assert(base);
1283
2.11M
    }
1284
1285
    /* Clear the instance dict (if any), to break cycles involving only
1286
       __dict__ slots (as in the case 'self.__dict__ is self'). */
1287
1.85M
    if (type->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
Line
Count
Source
359
1.85M
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
  Branch (1287:9): [True: 1.84M, False: 17.9k]
1288
1.84M
        _PyObject_ClearInstanceAttributes(self);
1289
1.84M
    }
1290
1.85M
    if (type->tp_dictoffset != base->tp_dictoffset) {
  Branch (1290:9): [True: 1.84M, False: 17.3k]
1291
1.84M
        PyObject **dictptr = _PyObject_DictPointer(self);
1292
1.84M
        if (dictptr && *dictptr)
  Branch (1292:13): [True: 1.84M, False: 0]
  Branch (1292:24): [True: 45.5k, False: 1.79M]
1293
45.5k
            Py_CLEAR(*dictptr);
Line
Count
Source
587
45.5k
    do {                                        \
588
45.5k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
45.5k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
45.5k
#  define _Py_CAST(type, expr) ((type)(expr))
589
45.5k
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 45.5k, False: 0]
590
45.5k
            (op) = NULL;                        \
591
45.5k
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
45.5k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
45.5k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
45.5k
#  define _Py_CAST(type, expr) ((type)(expr))
592
45.5k
        }                                       \
593
45.5k
    } while (0)
  Branch (593:14): [Folded - Ignored]
1294
1.84M
    }
1295
1296
1.85M
    if (baseclear)
  Branch (1296:9): [True: 18.6k, False: 1.84M]
1297
18.6k
        return baseclear(self);
1298
1.84M
    return 0;
1299
1.85M
}
1300
1301
static void
1302
subtype_dealloc(PyObject *self)
1303
13.3M
{
1304
13.3M
    PyTypeObject *type, *base;
1305
13.3M
    destructor basedealloc;
1306
13.3M
    int has_finalizer;
1307
1308
    /* Extract the type; we expect it to be a heap type */
1309
13.3M
    type = Py_TYPE(self);
Line
Count
Source
138
13.3M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
13.3M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.3M
#  define _Py_CAST(type, expr) ((type)(expr))
1310
13.3M
    _PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE);
Line
Count
Source
390
13.3M
    _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
Line
Count
Source
388
13.3M
    _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
Line
Count
Source
377
13.3M
    ((void)0)
1311
1312
    /* Test whether the type has GC exactly once */
1313
1314
13.3M
    if (!_PyType_IS_GC(type)) {
Line
Count
Source
222
13.3M
#define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
Line
Count
Source
394
13.3M
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (1314:9): [True: 263, False: 13.3M]
1315
        /* A non GC dynamic type allows certain simplifications:
1316
           there's no need to call clear_slots(), or DECREF the dict,
1317
           or clear weakrefs. */
1318
1319
        /* Maybe call finalizer; exit early if resurrected */
1320
263
        if (type->tp_finalize) {
  Branch (1320:13): [True: 5, False: 258]
1321
5
            if (PyObject_CallFinalizerFromDealloc(self) < 0)
  Branch (1321:17): [True: 2, False: 3]
1322
2
                return;
1323
5
        }
1324
261
        if (type->tp_del) {
  Branch (1324:13): [True: 0, False: 261]
1325
0
            type->tp_del(self);
1326
0
            if (Py_REFCNT(self) > 0) {
Line
Count
Source
129
0
#  define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1326:17): [True: 0, False: 0]
1327
0
                return;
1328
0
            }
1329
0
        }
1330
1331
        /* Find the nearest base with a different tp_dealloc */
1332
261
        base = type;
1333
525
        while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
  Branch (1333:16): [True: 264, False: 261]
1334
264
            base = base->tp_base;
1335
264
            assert(base);
1336
264
        }
1337
1338
        /* Extract the type again; tp_del may have changed it */
1339
261
        type = Py_TYPE(self);
Line
Count
Source
138
261
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
261
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
261
#  define _Py_CAST(type, expr) ((type)(expr))
1340
1341
        // Don't read type memory after calling basedealloc() since basedealloc()
1342
        // can deallocate the type and free its memory.
1343
261
        int type_needs_decref = (type->tp_flags & Py_TPFLAGS_HEAPTYPE
Line
Count
Source
375
522
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (1343:34): [True: 261, False: 0]
1344
261
                                 && !(base->tp_flags & Py_TPFLAGS_HEAPTYPE));
Line
Count
Source
375
261
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (1344:37): [True: 23, False: 238]
1345
1346
261
        assert((type->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0);
1347
1348
        /* Call the base tp_dealloc() */
1349
261
        assert(basedealloc);
1350
261
        basedealloc(self);
1351
1352
        /* Can't reference self beyond this point. It's possible tp_del switched
1353
           our type from a HEAPTYPE to a non-HEAPTYPE, so be careful about
1354
           reference counting. Only decref if the base type is not already a heap
1355
           allocated type. Otherwise, basedealloc should have decref'd it already */
1356
261
        if (type_needs_decref) {
  Branch (1356:13): [True: 23, False: 238]
1357
23
            Py_DECREF(type);
Line
Count
Source
548
23
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
23
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
23
#  define _Py_CAST(type, expr) ((type)(expr))
1358
23
        }
1359
1360
        /* Done */
1361
261
        return;
1362
261
    }
1363
1364
    /* We get here only if the type has GC */
1365
1366
    /* UnTrack and re-Track around the trashcan macro, alas */
1367
    /* See explanation at end of function for full disclosure */
1368
13.3M
    PyObject_GC_UnTrack(self);
1369
13.3M
    Py_TRASHCAN_BEGIN(self, subtype_dealloc);
Line
Count
Source
496
13.3M
    Py_TRASHCAN_BEGIN_CONDITION((op), \
Line
Count
Source
478
13.3M
    do { \
479
13.3M
        PyThreadState *_tstate = NULL; \
480
13.3M
        /* If "cond" is false, then _tstate remains NULL and the deallocator \
481
13.3M
         * is run normally without involving the trashcan */ \
482
13.3M
        if (cond) { \
  Branch (482:13): [True: 13.3M, False: 0]
483
13.3M
            _tstate = PyThreadState_Get(); \
484
13.3M
            if (_PyTrash_begin(_tstate, _PyObject_CAST(op))) { \
Line
Count
Source
109
13.3M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.3M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (484:17): [True: 2.51k, False: 13.3M]
485
2.51k
                break; \
486
2.51k
            } \
487
13.3M
        }
497
13.3M
        _PyTrash_cond(_PyObject_CAST(op), (destructor)(dealloc)))
1370
1371
    /* Find the nearest base with a different tp_dealloc */
1372
13.3M
    base = type;
1373
35.3M
    while ((/*basedealloc =*/ base->tp_dealloc) == subtype_dealloc) {
  Branch (1373:12): [True: 21.9M, False: 13.3M]
1374
21.9M
        base = base->tp_base;
1375
21.9M
        assert(base);
1376
21.9M
    }
1377
1378
13.3M
    has_finalizer = type->tp_finalize || type->tp_del;
  Branch (1378:21): [True: 274k, False: 13.1M]
  Branch (1378:42): [True: 6, False: 13.1M]
1379
1380
13.3M
    if (type->tp_finalize) {
  Branch (1380:9): [True: 274k, False: 13.1M]
1381
274k
        _PyObject_GC_TRACK(self);
Line
Count
Source
185
274k
        _PyObject_GC_TRACK(_PyObject_CAST(op))
Line
Count
Source
109
274k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
274k
#  define _Py_CAST(type, expr) ((type)(expr))
1382
274k
        if (PyObject_CallFinalizerFromDealloc(self) < 0) {
  Branch (1382:13): [True: 41, False: 274k]
1383
            /* Resurrected */
1384
41
            goto endlabel;
1385
41
        }
1386
274k
        _PyObject_GC_UNTRACK(self);
Line
Count
Source
187
274k
        _PyObject_GC_UNTRACK(_PyObject_CAST(op))
Line
Count
Source
109
274k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
274k
#  define _Py_CAST(type, expr) ((type)(expr))
1387
274k
    }
1388
    /*
1389
      If we added a weaklist, we clear it. Do this *before* calling tp_del,
1390
      clearing slots, or clearing the instance dict.
1391
1392
      GC tracking must be off at this point. weakref callbacks (if any, and
1393
      whether directly here or indirectly in something we call) may trigger GC,
1394
      and if self is tracked at that point, it will look like trash to GC and GC
1395
      will try to delete self again.
1396
    */
1397
13.3M
    if (type->tp_weaklistoffset && !base->tp_weaklistoffset) {
  Branch (1397:9): [True: 10.4M, False: 2.90M]
  Branch (1397:36): [True: 10.4M, False: 86.3k]
1398
10.4M
        PyObject_ClearWeakRefs(self);
1399
10.4M
    }
1400
1401
13.3M
    if (type->tp_del) {
  Branch (1401:9): [True: 11, False: 13.3M]
1402
11
        _PyObject_GC_TRACK(self);
Line
Count
Source
185
11
        _PyObject_GC_TRACK(_PyObject_CAST(op))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
1403
11
        type->tp_del(self);
1404
11
        if (Py_REFCNT(self) > 0) {
Line
Count
Source
129
11
#  define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1404:13): [True: 2, False: 9]
1405
            /* Resurrected */
1406
2
            goto endlabel;
1407
2
        }
1408
9
        _PyObject_GC_UNTRACK(self);
Line
Count
Source
187
9
        _PyObject_GC_UNTRACK(_PyObject_CAST(op))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
1409
9
    }
1410
13.3M
    if (has_finalizer) {
  Branch (1410:9): [True: 274k, False: 13.1M]
1411
        /* New weakrefs could be created during the finalizer call.
1412
           If this occurs, clear them out without calling their
1413
           finalizers since they might rely on part of the object
1414
           being finalized that has already been destroyed. */
1415
274k
        if (type->tp_weaklistoffset && !base->tp_weaklistoffset) {
  Branch (1415:13): [True: 274k, False: 20]
  Branch (1415:40): [True: 218k, False: 55.6k]
1416
            /* Modeled after GET_WEAKREFS_LISTPTR() */
1417
218k
            PyWeakReference **list = (PyWeakReference **) \
1418
218k
                _PyObject_GET_WEAKREFS_LISTPTR(self);
1419
218k
            while (*list)
  Branch (1419:20): [True: 0, False: 218k]
1420
0
                _PyWeakref_ClearRef(*list);
1421
218k
        }
1422
274k
    }
1423
1424
    /*  Clear slots up to the nearest base with a different tp_dealloc */
1425
13.3M
    base = type;
1426
35.3M
    while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
  Branch (1426:12): [True: 21.9M, False: 13.3M]
1427
21.9M
        if (Py_SIZE(base))
Line
Count
Source
147
21.9M
#  define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
Line
Count
Source
109
21.9M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21.9M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (147:23): [True: 2.15M, False: 19.7M]
1428
2.15M
            clear_slots(base, self);
1429
21.9M
        base = base->tp_base;
1430
21.9M
        assert(base);
1431
21.9M
    }
1432
1433
    /* If we added a dict, DECREF it, or free inline values. */
1434
13.3M
    if (type->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
Line
Count
Source
359
13.3M
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
  Branch (1434:9): [True: 9.24M, False: 4.15M]
1435
9.24M
        PyObject **dictptr = _PyObject_ManagedDictPointer(self);
1436
9.24M
        if (*dictptr != NULL) {
  Branch (1436:13): [True: 872k, False: 8.37M]
1437
872k
            assert(*_PyObject_ValuesPointer(self) == NULL);
1438
872k
            Py_DECREF(*dictptr);
Line
Count
Source
548
872k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
872k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
872k
#  define _Py_CAST(type, expr) ((type)(expr))
1439
872k
            *dictptr = NULL;
1440
872k
        }
1441
8.37M
        else {
1442
8.37M
            _PyObject_FreeInstanceAttributes(self);
1443
8.37M
        }
1444
9.24M
    }
1445
4.15M
    else if (type->tp_dictoffset && !base->tp_dictoffset) {
  Branch (1445:14): [True: 1.77M, False: 2.37M]
  Branch (1445:37): [True: 760k, False: 1.01M]
1446
760k
        PyObject **dictptr = _PyObject_DictPointer(self);
1447
760k
        if (dictptr != NULL) {
  Branch (1447:13): [True: 760k, False: 0]
1448
760k
            PyObject *dict = *dictptr;
1449
760k
            if (dict != NULL) {
  Branch (1449:17): [True: 257k, False: 502k]
1450
257k
                Py_DECREF(dict);
Line
Count
Source
548
257k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
257k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
257k
#  define _Py_CAST(type, expr) ((type)(expr))
1451
257k
                *dictptr = NULL;
1452
257k
            }
1453
760k
        }
1454
760k
    }
1455
1456
    /* Extract the type again; tp_del may have changed it */
1457
13.3M
    type = Py_TYPE(self);
Line
Count
Source
138
13.3M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
13.3M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.3M
#  define _Py_CAST(type, expr) ((type)(expr))
1458
1459
    /* Call the base tp_dealloc(); first retrack self if
1460
     * basedealloc knows about gc.
1461
     */
1462
13.3M
    if (_PyType_IS_GC(base)) {
Line
Count
Source
222
13.3M
#define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
Line
Count
Source
394
13.3M
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (222:26): [True: 2.79M, False: 10.6M]
1463
2.79M
        _PyObject_GC_TRACK(self);
Line
Count
Source
185
2.79M
        _PyObject_GC_TRACK(_PyObject_CAST(op))
Line
Count
Source
109
2.79M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.79M
#  define _Py_CAST(type, expr) ((type)(expr))
1464
2.79M
    }
1465
1466
    // Don't read type memory after calling basedealloc() since basedealloc()
1467
    // can deallocate the type and free its memory.
1468
13.3M
    int type_needs_decref = (type->tp_flags & Py_TPFLAGS_HEAPTYPE
Line
Count
Source
375
26.7M
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (1468:30): [True: 13.3M, False: 0]
1469
13.3M
                             && !(base->tp_flags & Py_TPFLAGS_HEAPTYPE));
Line
Count
Source
375
13.3M
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (1469:33): [True: 12.5M, False: 856k]
1470
1471
13.3M
    assert(basedealloc);
1472
13.3M
    basedealloc(self);
1473
1474
    /* Can't reference self beyond this point. It's possible tp_del switched
1475
       our type from a HEAPTYPE to a non-HEAPTYPE, so be careful about
1476
       reference counting. Only decref if the base type is not already a heap
1477
       allocated type. Otherwise, basedealloc should have decref'd it already */
1478
13.3M
    if (type_needs_decref) {
  Branch (1478:9): [True: 12.5M, False: 856k]
1479
12.5M
        Py_DECREF(type);
Line
Count
Source
548
12.5M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
12.5M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12.5M
#  define _Py_CAST(type, expr) ((type)(expr))
1480
12.5M
    }
1481
1482
13.3M
  endlabel:
1483
13.3M
    Py_TRASHCAN_END
Line
Count
Source
490
13.3M
        if (_tstate) { \
  Branch (490:13): [True: 13.3M, False: 0]
491
13.3M
            _PyTrash_end(_tstate); \
492
13.3M
        } \
493
13.3M
    } while (0);
  Branch (493:14): [Folded - Ignored]
1484
1485
    /* Explanation of the weirdness around the trashcan macros:
1486
1487
       Q. What do the trashcan macros do?
1488
1489
       A. Read the comment titled "Trashcan mechanism" in object.h.
1490
          For one, this explains why there must be a call to GC-untrack
1491
          before the trashcan begin macro.      Without understanding the
1492
          trashcan code, the answers to the following questions don't make
1493
          sense.
1494
1495
       Q. Why do we GC-untrack before the trashcan and then immediately
1496
          GC-track again afterward?
1497
1498
       A. In the case that the base class is GC-aware, the base class
1499
          probably GC-untracks the object.      If it does that using the
1500
          UNTRACK macro, this will crash when the object is already
1501
          untracked.  Because we don't know what the base class does, the
1502
          only safe thing is to make sure the object is tracked when we
1503
          call the base class dealloc.  But...  The trashcan begin macro
1504
          requires that the object is *untracked* before it is called.  So
1505
          the dance becomes:
1506
1507
         GC untrack
1508
         trashcan begin
1509
         GC track
1510
1511
       Q. Why did the last question say "immediately GC-track again"?
1512
          It's nowhere near immediately.
1513
1514
       A. Because the code *used* to re-track immediately.      Bad Idea.
1515
          self has a refcount of 0, and if gc ever gets its hands on it
1516
          (which can happen if any weakref callback gets invoked), it
1517
          looks like trash to gc too, and gc also tries to delete self
1518
          then.  But we're already deleting self.  Double deallocation is
1519
          a subtle disaster.
1520
    */
1521
13.3M
}
1522
1523
static PyTypeObject *solid_base(PyTypeObject *type);
1524
1525
/* type test with subclassing support */
1526
1527
static int
1528
type_is_subtype_base_chain(PyTypeObject *a, PyTypeObject *b)
1529
20.5k
{
1530
67.8k
    do {
1531
67.8k
        if (a == b)
  Branch (1531:13): [True: 20.4k, False: 47.3k]
1532
20.4k
            return 1;
1533
47.3k
        a = a->tp_base;
1534
47.3k
    } while (a != NULL);
  Branch (1534:14): [True: 47.2k, False: 77]
1535
1536
77
    return (b == &PyBaseObject_Type);
1537
20.5k
}
1538
1539
int
1540
PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b)
1541
93.1M
{
1542
93.1M
    PyObject *mro;
1543
1544
93.1M
    mro = a->tp_mro;
1545
93.1M
    if (mro != NULL) {
  Branch (1545:9): [True: 93.1M, False: 20.4k]
1546
        /* Deal with multiple inheritance without recursion
1547
           by walking the MRO tuple */
1548
93.1M
        Py_ssize_t i, n;
1549
93.1M
        assert(PyTuple_Check(mro));
1550
93.1M
        n = PyTuple_GET_SIZE(mro);
Line
Count
Source
26
93.1M
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
93.1M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
93.1M
#  define _Py_CAST(type, expr) ((type)(expr))
1551
264M
        for (i = 0; i < n; i++) {
  Branch (1551:21): [True: 221M, False: 42.7M]
1552
221M
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
Line
Count
Source
28
221M
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
221M
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
221M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1552:17): [True: 50.3M, False: 170M]
1553
50.3M
                return 1;
1554
221M
        }
1555
42.7M
        return 0;
1556
93.1M
    }
1557
20.4k
    else
1558
        /* a is not completely initialized yet; follow tp_base */
1559
20.4k
        return type_is_subtype_base_chain(a, b);
1560
93.1M
}
1561
1562
/* Routines to do a method lookup in the type without looking in the
1563
   instance dictionary (so we can't use PyObject_GetAttr) but still
1564
   binding it to the instance.
1565
1566
   Variants:
1567
1568
   - _PyObject_LookupSpecial() returns NULL without raising an exception
1569
     when the _PyType_Lookup() call fails;
1570
1571
   - lookup_maybe_method() and lookup_method() are internal routines similar
1572
     to _PyObject_LookupSpecial(), but can return unbound PyFunction
1573
     to avoid temporary method object. Pass self as first argument when
1574
     unbound == 1.
1575
*/
1576
1577
PyObject *
1578
_PyObject_LookupSpecial(PyObject *self, PyObject *attr)
1579
16.2M
{
1580
16.2M
    PyObject *res;
1581
1582
16.2M
    res = _PyType_Lookup(Py_TYPE(self), attr);
Line
Count
Source
138
16.2M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16.2M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16.2M
#  define _Py_CAST(type, expr) ((type)(expr))
1583
16.2M
    if (res != NULL) {
  Branch (1583:9): [True: 14.1M, False: 2.12M]
1584
14.1M
        descrgetfunc f;
1585
14.1M
        if ((f = Py_TYPE(res)->tp_descr_get) == NULL)
Line
Count
Source
138
14.1M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
14.1M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14.1M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1585:13): [True: 29, False: 14.1M]
1586
29
            Py_INCREF(res);
Line
Count
Source
512
29
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
29
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
29
#  define _Py_CAST(type, expr) ((type)(expr))
1587
14.1M
        else
1588
14.1M
            res = f(res, self, (PyObject *)(Py_TYPE(self)));
Line
Count
Source
138
14.1M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
14.1M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14.1M
#  define _Py_CAST(type, expr) ((type)(expr))
1589
14.1M
    }
1590
16.2M
    return res;
1591
16.2M
}
1592
1593
PyObject *
1594
_PyObject_LookupSpecialId(PyObject *self, _Py_Identifier *attrid)
1595
11
{
1596
11
    PyObject *attr = _PyUnicode_FromId(attrid);   /* borrowed */
1597
11
    if (attr == NULL)
  Branch (1597:9): [True: 0, False: 11]
1598
0
        return NULL;
1599
11
    return _PyObject_LookupSpecial(self, attr);
1600
11
}
1601
1602
static PyObject *
1603
lookup_maybe_method(PyObject *self, PyObject *attr, int *unbound)
1604
27.5M
{
1605
27.5M
    PyObject *res = _PyType_Lookup(Py_TYPE(self), attr);
Line
Count
Source
138
27.5M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
27.5M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
27.5M
#  define _Py_CAST(type, expr) ((type)(expr))
1606
27.5M
    if (res == NULL) {
  Branch (1606:9): [True: 33, False: 27.5M]
1607
33
        return NULL;
1608
33
    }
1609
1610
27.5M
    if (_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
Line
Count
Source
138
27.5M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
27.5M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
27.5M
#  define _Py_CAST(type, expr) ((type)(expr))
    if (_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
Line
Count
Source
404
27.5M
#define Py_TPFLAGS_METHOD_DESCRIPTOR (1UL << 17)
  Branch (1610:9): [True: 27.5M, False: 2.68k]
1611
        /* Avoid temporary PyMethodObject */
1612
27.5M
        *unbound = 1;
1613
27.5M
        Py_INCREF(res);
Line
Count
Source
512
27.5M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
27.5M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
27.5M
#  define _Py_CAST(type, expr) ((type)(expr))
1614
27.5M
    }
1615
2.68k
    else {
1616
2.68k
        *unbound = 0;
1617
2.68k
        descrgetfunc f = Py_TYPE(res)->tp_descr_get;
Line
Count
Source
138
2.68k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.68k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.68k
#  define _Py_CAST(type, expr) ((type)(expr))
1618
2.68k
        if (f == NULL) {
  Branch (1618:13): [True: 2.39k, False: 287]
1619
2.39k
            Py_INCREF(res);
Line
Count
Source
512
2.39k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
2.39k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.39k
#  define _Py_CAST(type, expr) ((type)(expr))
1620
2.39k
        }
1621
287
        else {
1622
287
            res = f(res, self, (PyObject *)(Py_TYPE(self)));
Line
Count
Source
138
287
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
287
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
287
#  define _Py_CAST(type, expr) ((type)(expr))
1623
287
        }
1624
2.68k
    }
1625
27.5M
    return res;
1626
27.5M
}
1627
1628
static PyObject *
1629
lookup_method(PyObject *self, PyObject *attr, int *unbound)
1630
15.2M
{
1631
15.2M
    PyObject *res = lookup_maybe_method(self, attr, unbound);
1632
15.2M
    if (res == NULL && !PyErr_Occurred()) {
  Branch (1632:9): [True: 2, False: 15.2M]
  Branch (1632:24): [True: 0, False: 2]
1633
0
        PyErr_SetObject(PyExc_AttributeError, attr);
1634
0
    }
1635
15.2M
    return res;
1636
15.2M
}
1637
1638
1639
static inline PyObject*
1640
vectorcall_unbound(PyThreadState *tstate, int unbound, PyObject *func,
1641
                   PyObject *const *args, Py_ssize_t nargs)
1642
14.6M
{
1643
14.6M
    size_t nargsf = nargs;
1644
14.6M
    if (!unbound) {
  Branch (1644:9): [True: 518, False: 14.6M]
1645
        /* Skip self argument, freeing up args[0] to use for
1646
         * PY_VECTORCALL_ARGUMENTS_OFFSET */
1647
518
        args++;
1648
518
        nargsf = nargsf - 1 + PY_VECTORCALL_ARGUMENTS_OFFSET;
Line
Count
Source
54
518
    (_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))
Line
Count
Source
70
518
#  define _Py_STATIC_CAST(type, expr) ((type)(expr))
1649
518
    }
1650
14.6M
    EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_SLOT, func);
Line
Count
Source
284
14.6M
#define EVAL_CALL_STAT_INC_IF_FUNCTION(name, callable) ((void)0)
1651
14.6M
    return _PyObject_VectorcallTstate(tstate, func, args, nargsf, NULL);
1652
14.6M
}
1653
1654
static PyObject*
1655
call_unbound_noarg(int unbound, PyObject *func, PyObject *self)
1656
1.68M
{
1657
1.68M
    if (unbound) {
  Branch (1657:9): [True: 1.68M, False: 164]
1658
1.68M
        return PyObject_CallOneArg(func, self);
1659
1.68M
    }
1660
164
    else {
1661
164
        return _PyObject_CallNoArgs(func);
1662
164
    }
1663
1.68M
}
1664
1665
/* A variation of PyObject_CallMethod* that uses lookup_method()
1666
   instead of PyObject_GetAttrString().
1667
1668
   args is an argument vector of length nargs. The first element in this
1669
   vector is the special object "self" which is used for the method lookup */
1670
static PyObject *
1671
vectorcall_method(PyObject *name, PyObject *const *args, Py_ssize_t nargs)
1672
4.08M
{
1673
4.08M
    assert(nargs >= 1);
1674
1675
4.08M
    PyThreadState *tstate = _PyThreadState_GET();
1676
4.08M
    int unbound;
1677
4.08M
    PyObject *self = args[0];
1678
4.08M
    PyObject *func = lookup_method(self, name, &unbound);
1679
4.08M
    if (func == NULL) {
  Branch (1679:9): [True: 1, False: 4.08M]
1680
1
        return NULL;
1681
1
    }
1682
4.08M
    PyObject *retval = vectorcall_unbound(tstate, unbound, func, args, nargs);
1683
4.08M
    Py_DECREF(func);
Line
Count
Source
548
4.08M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4.08M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4.08M
#  define _Py_CAST(type, expr) ((type)(expr))
1684
4.08M
    return retval;
1685
4.08M
}
1686
1687
/* Clone of vectorcall_method() that returns NotImplemented
1688
 * when the lookup fails. */
1689
static PyObject *
1690
vectorcall_maybe(PyThreadState *tstate, PyObject *name,
1691
                 PyObject *const *args, Py_ssize_t nargs)
1692
500k
{
1693
500k
    assert(nargs >= 1);
1694
1695
500k
    int unbound;
1696
500k
    PyObject *self = args[0];
1697
500k
    PyObject *func = lookup_maybe_method(self, name, &unbound);
1698
500k
    if (func == NULL) {
  Branch (1698:9): [True: 33, False: 500k]
1699
33
        if (!PyErr_Occurred())
  Branch (1699:13): [True: 33, False: 0]
1700
33
            Py_RETURN_NOTIMPLEMENTED;
Line
Count
Source
671
33
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
33
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
33
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
33
#  define _Py_CAST(type, expr) ((type)(expr))
1701
0
        return NULL;
1702
33
    }
1703
500k
    PyObject *retval = vectorcall_unbound(tstate, unbound, func, args, nargs);
1704
500k
    Py_DECREF(func);
Line
Count
Source
548
500k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
500k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
500k
#  define _Py_CAST(type, expr) ((type)(expr))
1705
500k
    return retval;
1706
500k
}
1707
1708
/*
1709
    Method resolution order algorithm C3 described in
1710
    "A Monotonic Superclass Linearization for Dylan",
1711
    by Kim Barrett, Bob Cassel, Paul Haahr,
1712
    David A. Moon, Keith Playford, and P. Tucker Withington.
1713
    (OOPSLA 1996)
1714
1715
    Some notes about the rules implied by C3:
1716
1717
    No duplicate bases.
1718
    It isn't legal to repeat a class in a list of base classes.
1719
1720
    The next three properties are the 3 constraints in "C3".
1721
1722
    Local precedence order.
1723
    If A precedes B in C's MRO, then A will precede B in the MRO of all
1724
    subclasses of C.
1725
1726
    Monotonicity.
1727
    The MRO of a class must be an extension without reordering of the
1728
    MRO of each of its superclasses.
1729
1730
    Extended Precedence Graph (EPG).
1731
    Linearization is consistent if there is a path in the EPG from
1732
    each class to all its successors in the linearization.  See
1733
    the paper for definition of EPG.
1734
 */
1735
1736
static int
1737
tail_contains(PyObject *tuple, int whence, PyObject *o)
1738
255k
{
1739
255k
    Py_ssize_t j, size;
1740
255k
    size = PyTuple_GET_SIZE(tuple);
Line
Count
Source
26
255k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
255k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
255k
#  define _Py_CAST(type, expr) ((type)(expr))
1741
1742
435k
    for (j = whence+1; j < size; j++) {
  Branch (1742:24): [True: 207k, False: 228k]
1743
207k
        if (PyTuple_GET_ITEM(tuple, j) == o)
Line
Count
Source
28
207k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
207k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
207k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1743:13): [True: 27.0k, False: 180k]
1744
27.0k
            return 1;
1745
207k
    }
1746
228k
    return 0;
1747
255k
}
1748
1749
static PyObject *
1750
class_name(PyObject *cls)
1751
26
{
1752
26
    PyObject *name;
1753
26
    if (_PyObject_LookupAttr(cls, &_Py_ID(__name__), &name) == 0) {
Line
Count
Source
374
26
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
26
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
26
    _PyRuntime.global_objects.NAME
  Branch (1753:9): [True: 0, False: 26]
1754
0
        name = PyObject_Repr(cls);
1755
0
    }
1756
26
    return name;
1757
26
}
1758
1759
static int
1760
check_duplicates(PyObject *tuple)
1761
13.9k
{
1762
13.9k
    Py_ssize_t i, j, n;
1763
    /* Let's use a quadratic time algorithm,
1764
       assuming that the bases tuples is short.
1765
    */
1766
13.9k
    n = PyTuple_GET_SIZE(tuple);
Line
Count
Source
26
13.9k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
13.9k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.9k
#  define _Py_CAST(type, expr) ((type)(expr))
1767
42.4k
    for (i = 0; i < n; i++) {
  Branch (1767:17): [True: 28.5k, False: 13.9k]
1768
28.5k
        PyObject *o = PyTuple_GET_ITEM(tuple, i);
Line
Count
Source
28
28.5k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
28.5k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
28.5k
#  define _Py_CAST(type, expr) ((type)(expr))
1769
44.2k
        for (j = i + 1; j < n; j++) {
  Branch (1769:25): [True: 15.7k, False: 28.5k]
1770
15.7k
            if (PyTuple_GET_ITEM(tuple, j) == o) {
Line
Count
Source
28
15.7k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
15.7k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
15.7k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1770:17): [True: 5, False: 15.7k]
1771
5
                o = class_name(o);
1772
5
                if (o != NULL) {
  Branch (1772:21): [True: 5, False: 0]
1773
5
                    if (PyUnicode_Check(o)) {
Line
Count
Source
115
5
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
5
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 5, False: 0]
1774
5
                        PyErr_Format(PyExc_TypeError,
1775
5
                                     "duplicate base class %U", o);
1776
5
                    }
1777
0
                    else {
1778
0
                        PyErr_SetString(PyExc_TypeError,
1779
0
                                        "duplicate base class");
1780
0
                    }
1781
5
                    Py_DECREF(o);
Line
Count
Source
548
5
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
1782
5
                }
1783
5
                return -1;
1784
5
            }
1785
15.7k
        }
1786
28.5k
    }
1787
13.9k
    return 0;
1788
13.9k
}
1789
1790
/* Raise a TypeError for an MRO order disagreement.
1791
1792
   It's hard to produce a good error message.  In the absence of better
1793
   insight into error reporting, report the classes that were candidates
1794
   to be put next into the MRO.  There is some conflict between the
1795
   order in which they should be put in the MRO, but it's hard to
1796
   diagnose what constraint can't be satisfied.
1797
*/
1798
1799
static void
1800
set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, int *remain)
1801
10
{
1802
10
    Py_ssize_t i, n, off;
1803
10
    char buf[1000];
1804
10
    PyObject *k, *v;
1805
10
    PyObject *set = PyDict_New();
1806
10
    if (!set) return;
  Branch (1806:9): [True: 0, False: 10]
1807
1808
41
    for (i = 0; i < to_merge_size; i++) {
  Branch (1808:17): [True: 31, False: 10]
1809
31
        PyObject *L = to_merge[i];
1810
31
        if (remain[i] < PyTuple_GET_SIZE(L)) {
Line
Count
Source
26
31
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
31
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
31
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1810:13): [True: 27, False: 4]
1811
27
            PyObject *c = PyTuple_GET_ITEM(L, remain[i]);
Line
Count
Source
28
27
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
27
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
27
#  define _Py_CAST(type, expr) ((type)(expr))
1812
27
            if (PyDict_SetItem(set, c, Py_None) < 0) {
Line
Count
Source
654
27
#define Py_None (&_Py_NoneStruct)
  Branch (1812:17): [True: 0, False: 27]
1813
0
                Py_DECREF(set);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
1814
0
                return;
1815
0
            }
1816
27
        }
1817
31
    }
1818
10
    n = PyDict_GET_SIZE(set);
Line
Count
Source
55
10
#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
1819
1820
10
    off = PyOS_snprintf(buf, sizeof(buf), "Cannot create a \
1821
10
consistent method resolution\norder (MRO) for bases");
1822
10
    i = 0;
1823
31
    while (PyDict_Next(set, &i, &k, &v) && (size_t)off < sizeof(buf)) {
  Branch (1823:12): [True: 21, False: 10]
  Branch (1823:44): [True: 21, False: 0]
1824
21
        PyObject *name = class_name(k);
1825
21
        const char *name_str = NULL;
1826
21
        if (name != NULL) {
  Branch (1826:13): [True: 21, False: 0]
1827
21
            if (PyUnicode_Check(name)) {
Line
Count
Source
115
21
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
21
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 21, False: 0]
1828
21
                name_str = PyUnicode_AsUTF8(name);
1829
21
            }
1830
0
            else {
1831
0
                name_str = "?";
1832
0
            }
1833
21
        }
1834
21
        if (name_str == NULL) {
  Branch (1834:13): [True: 0, False: 21]
1835
0
            Py_XDECREF(name);
Line
Count
Source
613
0
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
1836
0
            Py_DECREF(set);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
1837
0
            return;
1838
0
        }
1839
21
        off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s", name_str);
1840
21
        Py_XDECREF(name);
Line
Count
Source
613
21
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
21
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21
#  define _Py_CAST(type, expr) ((type)(expr))
1841
21
        if (--n && (size_t)(off+1) < sizeof(buf)) {
  Branch (1841:13): [True: 11, False: 10]
  Branch (1841:20): [True: 11, False: 0]
1842
11
            buf[off++] = ',';
1843
11
            buf[off] = '\0';
1844
11
        }
1845
21
    }
1846
10
    PyErr_SetString(PyExc_TypeError, buf);
1847
10
    Py_DECREF(set);
Line
Count
Source
548
10
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
1848
10
}
1849
1850
static int
1851
pmerge(PyObject *acc, PyObject **to_merge, Py_ssize_t to_merge_size)
1852
13.9k
{
1853
13.9k
    int res = 0;
1854
13.9k
    Py_ssize_t i, j, empty_cnt;
1855
13.9k
    int *remain;
1856
1857
    /* remain stores an index into each sublist of to_merge.
1858
       remain[i] is the index of the next base in to_merge[i]
1859
       that is not included in acc.
1860
    */
1861
13.9k
    remain = PyMem_New(int, to_merge_size);
Line
Count
Source
68
13.9k
  ( ((size_t)(n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL :      \
Line
Count
Source
180
13.9k
#   define PY_SSIZE_T_MAX SSIZE_MAX
  Branch (68:5): [True: 0, False: 13.9k]
69
13.9k
        ( (type *) PyMem_Malloc((n) * sizeof(type)) ) )
1862
13.9k
    if (remain == NULL) {
  Branch (1862:9): [True: 0, False: 13.9k]
1863
0
        PyErr_NoMemory();
1864
0
        return -1;
1865
0
    }
1866
56.3k
    for (i = 0; i < to_merge_size; i++)
  Branch (1866:17): [True: 42.4k, False: 13.9k]
1867
42.4k
        remain[i] = 0;
1868
1869
78.7k
  again:
1870
78.7k
    empty_cnt = 0;
1871
148k
    for (i = 0; i < to_merge_size; i++) {
  Branch (1871:17): [True: 134k, False: 13.9k]
1872
134k
        PyObject *candidate;
1873
1874
134k
        PyObject *cur_tuple = to_merge[i];
1875
1876
134k
        if (remain[i] >= PyTuple_GET_SIZE(cur_tuple)) {
Line
Count
Source
26
134k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
134k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
134k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1876:13): [True: 42.4k, False: 91.8k]
1877
42.4k
            empty_cnt++;
1878
42.4k
            continue;
1879
42.4k
        }
1880
1881
        /* Choose next candidate for MRO.
1882
1883
           The input sequences alone can determine the choice.
1884
           If not, choose the class which appears in the MRO
1885
           of the earliest direct superclass of the new class.
1886
        */
1887
1888
91.8k
        candidate = PyTuple_GET_ITEM(cur_tuple, remain[i]);
Line
Count
Source
28
91.8k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
91.8k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
91.8k
#  define _Py_CAST(type, expr) ((type)(expr))
1889
320k
        for (j = 0; j < to_merge_size; j++) {
  Branch (1889:21): [True: 255k, False: 64.8k]
1890
255k
            PyObject *j_lst = to_merge[j];
1891
255k
            if (tail_contains(j_lst, remain[j], candidate))
  Branch (1891:17): [True: 27.0k, False: 228k]
1892
27.0k
                goto skip; /* continue outer loop */
1893
255k
        }
1894
64.8k
        res = PyList_Append(acc, candidate);
1895
64.8k
        if (res < 0)
  Branch (1895:13): [True: 0, False: 64.8k]
1896
0
            goto out;
1897
1898
264k
        for (j = 0; j < to_merge_size; j++) {
  Branch (1898:21): [True: 199k, False: 64.8k]
1899
199k
            PyObject *j_lst = to_merge[j];
1900
199k
            if (remain[j] < PyTuple_GET_SIZE(j_lst) &&
Line
Count
Source
26
398k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
199k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
199k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1900:17): [True: 170k, False: 29.0k]
1901
199k
                PyTuple_GET_ITEM(j_lst, remain[j]) == candidate) {
Line
Count
Source
28
170k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
170k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
170k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (1901:17): [True: 112k, False: 57.5k]
1902
112k
                remain[j]++;
1903
112k
            }
1904
199k
        }
1905
64.8k
        goto again;
1906
27.0k
      skip: ;
1907
27.0k
    }
1908
1909
13.9k
    if (empty_cnt != to_merge_size) {
  Branch (1909:9): [True: 10, False: 13.9k]
1910
10
        set_mro_error(to_merge, to_merge_size, remain);
1911
10
        res = -1;
1912
10
    }
1913
1914
13.9k
  out:
1915
13.9k
    PyMem_Free(remain);
1916
1917
13.9k
    return res;
1918
13.9k
}
1919
1920
static PyObject *
1921
mro_implementation(PyTypeObject *type)
1922
115k
{
1923
115k
    if (!_PyType_IsReady(type)) {
Line
Count
Source
241
115k
#define _PyType_IsReady(type) ((type)->tp_dict != NULL)
  Branch (1923:9): [True: 0, False: 115k]
1924
0
        if (PyType_Ready(type) < 0)
  Branch (1924:13): [True: 0, False: 0]
1925
0
            return NULL;
1926
0
    }
1927
1928
115k
    PyObject *bases = type->tp_bases;
1929
115k
    Py_ssize_t n = PyTuple_GET_SIZE(bases);
Line
Count
Source
26
115k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
115k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
115k
#  define _Py_CAST(type, expr) ((type)(expr))
1930
244k
    for (Py_ssize_t i = 0; i < n; i++) {
  Branch (1930:28): [True: 129k, False: 115k]
1931
129k
        PyTypeObject *base = _PyType_CAST(PyTuple_GET_ITEM(bases, i));
Line
Count
Source
792
129k
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
129k
#  define _Py_CAST(type, expr) ((type)(expr))
1932
129k
        if (base->tp_mro == NULL) {
  Branch (1932:13): [True: 1, False: 129k]
1933
1
            PyErr_Format(PyExc_TypeError,
1934
1
                         "Cannot extend an incomplete type '%.100s'",
1935
1
                         base->tp_name);
1936
1
            return NULL;
1937
1
        }
1938
129k
        assert(PyTuple_Check(base->tp_mro));
1939
129k
    }
1940
1941
115k
    if (n == 1) {
  Branch (1941:9): [True: 101k, False: 13.9k]
1942
        /* Fast path: if there is a single base, constructing the MRO
1943
         * is trivial.
1944
         */
1945
101k
        PyTypeObject *base = _PyType_CAST(PyTuple_GET_ITEM(bases, 0));
Line
Count
Source
792
101k
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
101k
#  define _Py_CAST(type, expr) ((type)(expr))
1946
101k
        Py_ssize_t k = PyTuple_GET_SIZE(base->tp_mro);
Line
Count
Source
26
101k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
101k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
101k
#  define _Py_CAST(type, expr) ((type)(expr))
1947
101k
        PyObject *result = PyTuple_New(k + 1);
1948
101k
        if (result == NULL) {
  Branch (1948:13): [True: 0, False: 101k]
1949
0
            return NULL;
1950
0
        }
1951
1952
101k
        Py_INCREF(type);
Line
Count
Source
512
101k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
101k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
101k
#  define _Py_CAST(type, expr) ((type)(expr))
1953
101k
        PyTuple_SET_ITEM(result, 0, (PyObject *) type);
Line
Count
Source
37
101k
    PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
101k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
101k
#  define _Py_CAST(type, expr) ((type)(expr))
    PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
101k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
101k
#  define _Py_CAST(type, expr) ((type)(expr))
1954
343k
        for (Py_ssize_t i = 0; i < k; i++) {
  Branch (1954:32): [True: 241k, False: 101k]
1955
241k
            PyObject *cls = PyTuple_GET_ITEM(base->tp_mro, i);
Line
Count
Source
28
241k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
241k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
241k
#  define _Py_CAST(type, expr) ((type)(expr))
1956
241k
            Py_INCREF(cls);
Line
Count
Source
512
241k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
241k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
241k
#  define _Py_CAST(type, expr) ((type)(expr))
1957
241k
            PyTuple_SET_ITEM(result, i + 1, cls);
Line
Count
Source
37
241k
    PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
241k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
241k
#  define _Py_CAST(type, expr) ((type)(expr))
    PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
241k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
241k
#  define _Py_CAST(type, expr) ((type)(expr))
1958
241k
        }
1959
101k
        return result;
1960
101k
    }
1961
1962
    /* This is just a basic sanity check. */
1963
13.9k
    if (check_duplicates(bases) < 0) {
  Branch (1963:9): [True: 5, False: 13.9k]
1964
5
        return NULL;
1965
5
    }
1966
1967
    /* Find a superclass linearization that honors the constraints
1968
       of the explicit tuples of bases and the constraints implied by
1969
       each base class.
1970
1971
       to_merge is an array of tuples, where each tuple is a superclass
1972
       linearization implied by a base class.  The last element of
1973
       to_merge is the declared tuple of bases.
1974
    */
1975
13.9k
    PyObject **to_merge = PyMem_New(PyObject *, n + 1);
Line
Count
Source
68
13.9k
  ( ((size_t)(n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL :      \
Line
Count
Source
180
13.9k
#   define PY_SSIZE_T_MAX SSIZE_MAX
  Branch (68:5): [True: 0, False: 13.9k]
69
13.9k
        ( (type *) PyMem_Malloc((n) * sizeof(type)) ) )
1976
13.9k
    if (to_merge == NULL) {
  Branch (1976:9): [True: 0, False: 13.9k]
1977
0
        PyErr_NoMemory();
1978
0
        return NULL;
1979
0
    }
1980
1981
42.4k
    for (Py_ssize_t i = 0; i < n; i++) {
  Branch (1981:28): [True: 28.5k, False: 13.9k]
1982
28.5k
        PyTypeObject *base = _PyType_CAST(PyTuple_GET_ITEM(bases, i));
Line
Count
Source
792
28.5k
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
28.5k
#  define _Py_CAST(type, expr) ((type)(expr))
1983
28.5k
        to_merge[i] = base->tp_mro;
1984
28.5k
    }
1985
13.9k
    to_merge[n] = bases;
1986
1987
13.9k
    PyObject *result = PyList_New(1);
1988
13.9k
    if (result == NULL) {
  Branch (1988:9): [True: 0, False: 13.9k]
1989
0
        PyMem_Free(to_merge);
1990
0
        return NULL;
1991
0
    }
1992
1993
13.9k
    Py_INCREF(type);
Line
Count
Source
512
13.9k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
13.9k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.9k
#  define _Py_CAST(type, expr) ((type)(expr))
1994
13.9k
    PyList_SET_ITEM(result, 0, (PyObject *)type);
Line
Count
Source
47
13.9k
    PyList_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
13.9k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.9k
#  define _Py_CAST(type, expr) ((type)(expr))
    PyList_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
13.9k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.9k
#  define _Py_CAST(type, expr) ((type)(expr))
1995
13.9k
    if (pmerge(result, to_merge, n + 1) < 0) {
  Branch (1995:9): [True: 10, False: 13.9k]
1996
10
        Py_CLEAR(result);
Line
Count
Source
587
10
    do {                                        \
588
10
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
589
10
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 10, False: 0]
590
10
            (op) = NULL;                        \
591
10
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
10
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
592
10
        }                                       \
593
10
    } while (0)
  Branch (593:14): [Folded - Ignored]
1997
10
    }
1998
13.9k
    PyMem_Free(to_merge);
1999
2000
13.9k
    return result;
2001
13.9k
}
2002
2003
/*[clinic input]
2004
type.mro
2005
2006
Return a type's method resolution order.
2007
[clinic start generated code]*/
2008
2009
static PyObject *
2010
type_mro_impl(PyTypeObject *self)
2011
/*[clinic end generated code: output=bffc4a39b5b57027 input=28414f4e156db28d]*/
2012
17.5k
{
2013
17.5k
    PyObject *seq;
2014
17.5k
    seq = mro_implementation(self);
2015
17.5k
    if (seq != NULL && !PyList_Check(seq)) {
Line
Count
Source
25
17.5k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
Line
Count
Source
782
17.5k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (2015:9): [True: 17.5k, False: 6]
  Branch (2015:24): [True: 14.4k, False: 3.07k]
2016
14.4k
        Py_SETREF(seq, PySequence_List(seq));
Line
Count
Source
332
14.4k
    do {                                        \
333
14.4k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
14.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14.4k
#  define _Py_CAST(type, expr) ((type)(expr))
334
14.4k
        (op) = (op2);                           \
335
14.4k
        Py_DECREF(_py_tmp);                     \
Line
Count
Source
548
14.4k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
14.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14.4k
#  define _Py_CAST(type, expr) ((type)(expr))
336
14.4k
    } while (0)
  Branch (336:14): [Folded - Ignored]
2017
14.4k
    }
2018
17.5k
    return seq;
2019
17.5k
}
2020
2021
static int
2022
mro_check(PyTypeObject *type, PyObject *mro)
2023
17.4k
{
2024
17.4k
    PyTypeObject *solid;
2025
17.4k
    Py_ssize_t i, n;
2026
2027
17.4k
    solid = solid_base(type);
2028
2029
17.4k
    n = PyTuple_GET_SIZE(mro);
Line
Count
Source
26
17.4k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
17.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
17.4k
#  define _Py_CAST(type, expr) ((type)(expr))
2030
101k
    for (i = 0; i < n; i++) {
  Branch (2030:17): [True: 83.6k, False: 17.4k]
2031
83.6k
        PyObject *obj = PyTuple_GET_ITEM(mro, i);
Line
Count
Source
28
83.6k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
83.6k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
83.6k
#  define _Py_CAST(type, expr) ((type)(expr))
2032
83.6k
        if (!PyType_Check(obj)) {
Line
Count
Source
788
83.6k
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
83.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
83.6k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (2032:13): [True: 1, False: 83.6k]
2033
1
            PyErr_Format(
2034
1
                PyExc_TypeError,
2035
1
                "mro() returned a non-class ('%.500s')",
2036
1
                Py_TYPE(obj)->tp_name);
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
2037
1
            return -1;
2038
1
        }
2039
83.6k
        PyTypeObject *base = (PyTypeObject*)obj;
2040
2041
83.6k
        if (!PyType_IsSubtype(solid, solid_base(base))) {
  Branch (2041:13): [True: 1, False: 83.6k]
2042
1
            PyErr_Format(
2043
1
                PyExc_TypeError,
2044
1
                "mro() returned base with unsuitable layout ('%.500s')",
2045
1
                base->tp_name);
2046
1
            return -1;
2047
1
        }
2048
83.6k
    }
2049
2050
17.4k
    return 0;
2051
17.4k
}
2052
2053
/* Lookups an mcls.mro method, invokes it and checks the result (if needed,
2054
   in case of a custom mro() implementation).
2055
2056
   Keep in mind that during execution of this function type->tp_mro
2057
   can be replaced due to possible reentrance (for example,
2058
   through type_set_bases):
2059
2060
      - when looking up the mcls.mro attribute (it could be
2061
        a user-provided descriptor);
2062
2063
      - from inside a custom mro() itself;
2064
2065
      - through a finalizer of the return value of mro().
2066
*/
2067
static PyObject *
2068
mro_invoke(PyTypeObject *type)
2069
115k
{
2070
115k
    PyObject *mro_result;
2071
115k
    PyObject *new_mro;
2072
115k
    const int custom = !Py_IS_TYPE(type, &PyType_Type);
Line
Count
Source
155
115k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
115k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
115k
#  define _Py_CAST(type, expr) ((type)(expr))
2073
2074
115k
    if (custom) {
  Branch (2074:9): [True: 17.4k, False: 97.5k]
2075
17.4k
        int unbound;
2076
17.4k
        PyObject *mro_meth = lookup_method(
2077
17.4k
            (PyObject *)type, &_Py_ID(mro), &unbound);
Line
Count
Source
374
17.4k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
17.4k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
17.4k
    _PyRuntime.global_objects.NAME
2078
17.4k
        if (mro_meth == NULL)
  Branch (2078:13): [True: 0, False: 17.4k]
2079
0
            return NULL;
2080
17.4k
        mro_result = call_unbound_noarg(unbound, mro_meth, (PyObject *)type);
2081
17.4k
        Py_DECREF(mro_meth);
Line
Count
Source
548
17.4k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
17.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
17.4k
#  define _Py_CAST(type, expr) ((type)(expr))
2082
17.4k
    }
2083
97.5k
    else {
2084
97.5k
        mro_result = mro_implementation(type);
2085
97.5k
    }
2086
115k
    if (mro_result == NULL)
  Branch (2086:9): [True: 20, False: 114k]
2087
20
        return NULL;
2088
2089
114k
    new_mro = PySequence_Tuple(mro_result);
2090
114k
    Py_DECREF(mro_result);
Line
Count
Source
548
114k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
114k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
114k
#  define _Py_CAST(type, expr) ((type)(expr))
2091
114k
    if (new_mro == NULL) {
  Branch (2091:9): [True: 1, False: 114k]
2092
1
        return NULL;
2093
1
    }
2094
2095
114k
    if (PyTuple_GET_SIZE(new_mro) == 0) {
Line
Count
Source
26
114k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
114k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
114k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (2095:9): [True: 0, False: 114k]
2096
0
        Py_DECREF(new_mro);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
2097
0
        PyErr_Format(PyExc_TypeError, "type MRO must not be empty");
2098
0
        return NULL;
2099
0
    }
2100
2101
114k
    if (custom && mro_check(type, new_mro) < 0) {
  Branch (2101:9): [True: 17.4k, False: 97.5k]
  Branch (2101:19): [True: 2, False: 17.4k]
2102
2
        Py_DECREF(new_mro);
Line
Count
Source
548
2
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
2103
2
        return NULL;
2104
2
    }
2105
114k
    return new_mro;
2106
114k
}
2107
2108
/* Calculates and assigns a new MRO to type->tp_mro.
2109
   Return values and invariants:
2110
2111
     - Returns 1 if a new MRO value has been set to type->tp_mro due to
2112
       this call of mro_internal (no tricky reentrancy and no errors).
2113
2114
       In case if p_old_mro argument is not NULL, a previous value
2115
       of type->tp_mro is put there, and the ownership of this
2116
       reference is transferred to a caller.
2117
       Otherwise, the previous value (if any) is decref'ed.
2118
2119
     - Returns 0 in case when type->tp_mro gets changed because of
2120
       reentering here through a custom mro() (see a comment to mro_invoke).
2121
2122
       In this case, a refcount of an old type->tp_mro is adjusted
2123
       somewhere deeper in the call stack (by the innermost mro_internal
2124
       or its caller) and may become zero upon returning from here.
2125
       This also implies that the whole hierarchy of subclasses of the type
2126
       has seen the new value and updated their MRO accordingly.
2127
2128
     - Returns -1 in case of an error.
2129
*/
2130
static int
2131
mro_internal(PyTypeObject *type, PyObject **p_old_mro)
2132
115k
{
2133
115k
    PyObject *new_mro, *old_mro;
2134
115k
    int reent;
2135
2136
    /* Keep a reference to be able to do a reentrancy check below.
2137
       Don't let old_mro be GC'ed and its address be reused for
2138
       another object, like (suddenly!) a new tp_mro.  */
2139
115k
    old_mro = type->tp_mro;
2140
115k
    Py_XINCREF(old_mro);
Line
Count
Source
603
115k
#  define Py_XINCREF(op) Py_XINCREF(_PyObject_CAST(op))
Line
Count
Source
109
115k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
115k
#  define _Py_CAST(type, expr) ((type)(expr))
2141
115k
    new_mro = mro_invoke(type);  /* might cause reentrance */
2142
115k
    reent = (type->tp_mro != old_mro);
2143
115k
    Py_XDECREF(old_mro);
Line
Count
Source
613
115k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
115k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
115k
#  define _Py_CAST(type, expr) ((type)(expr))
2144
115k
    if (new_mro == NULL) {
  Branch (2144:9): [True: 23, False: 114k]
2145
23
        return -1;
2146
23
    }
2147
2148
114k
    if (reent) {
  Branch (2148:9): [True: 15, False: 114k]
2149
15
        Py_DECREF(new_mro);
Line
Count
Source
548
15
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
15
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
15
#  define _Py_CAST(type, expr) ((type)(expr))
2150
15
        return 0;
2151
15
    }
2152
2153
114k
    type->tp_mro = new_mro;
2154
2155
114k
    type_mro_modified(type, type->tp_mro);
2156
    /* corner case: the super class might have been hidden
2157
       from the custom MRO */
2158
114k
    type_mro_modified(type, type->tp_bases);
2159
2160
114k
    PyType_Modified(type);
2161
2162
114k
    if (p_old_mro != NULL)
  Branch (2162:9): [True: 142, False: 114k]
2163
142
        *p_old_mro = old_mro;  /* transfer the ownership */
2164
114k
    else
2165
114k
        Py_XDECREF(old_mro);
Line
Count
Source
613
114k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
114k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
114k
#  define _Py_CAST(type, expr) ((type)(expr))
2166
2167
114k
    return 1;
2168
114k
}
2169
2170
/* Calculate the best base amongst multiple base classes.
2171
   This is the first one that's on the path to the "solid base". */
2172
2173
static PyTypeObject *
2174
best_base(PyObject *bases)
2175
64.6k
{
2176
64.6k
    Py_ssize_t i, n;
2177
64.6k
    PyTypeObject *base, *winner, *candidate;
2178
2179
64.6k
    assert(PyTuple_Check(bases));
2180
64.6k
    n = PyTuple_GET_SIZE(bases);
Line
Count
Source
26
64.6k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
64.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
64.6k
#  define _Py_CAST(type, expr) ((type)(expr))
2181
64.6k
    assert(n > 0);
2182
64.6k
    base = NULL;
2183
64.6k
    winner = NULL;
2184
143k
    for (i = 0; i < n; i++) {
  Branch (2184:17): [True: 79.3k, False: 64.6k]
2185
79.3k
        PyObject *base_proto = PyTuple_GET_ITEM(bases, i);
Line
Count
Source
28
79.3k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
79.3k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
79.3k
#  define _Py_CAST(type, expr) ((type)(expr))
2186
79.3k
        if (!PyType_Check(base_proto)) {
Line
Count
Source
788
79.3k
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
79.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.3k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (2186:13): [True: 0, False: 79.3k]
2187
0
            PyErr_SetString(
2188
0
                PyExc_TypeError,
2189
0
                "bases must be types");
2190
0
            return NULL;
2191
0
        }
2192
79.3k
        PyTypeObject *base_i = (PyTypeObject *)base_proto;
2193
2194
79.3k
        if (!_PyType_IsReady(base_i)) {
Line
Count
Source
241
79.3k
#define _PyType_IsReady(type) ((type)->tp_dict != NULL)
  Branch (2194:13): [True: 1, False: 79.3k]
2195
1
            if (PyType_Ready(base_i) < 0)
  Branch (2195:17): [True: 0, False: 1]
2196
0
                return NULL;
2197
1
        }
2198
79.3k
        if (!_PyType_HasFeature(base_i, Py_TPFLAGS_BASETYPE)) {
Line
Count
Source
378
79.3k
#define Py_TPFLAGS_BASETYPE (1UL << 10)
  Branch (2198:13): [True: 17, False: 79.3k]
2199
17
            PyErr_Format(PyExc_TypeError,
2200
17
                         "type '%.100s' is not an acceptable base type",
2201
17
                         base_i->tp_name);
2202
17
            return NULL;
2203
17
        }
2204
79.3k
        candidate = solid_base(base_i);
2205
79.3k
        if (winner == NULL) {
  Branch (2205:13): [True: 64.6k, False: 14.7k]
2206
64.6k
            winner = candidate;
2207
64.6k
            base = base_i;
2208
64.6k
        }
2209
14.7k
        else if (PyType_IsSubtype(winner, candidate))
  Branch (2209:18): [True: 8.01k, False: 6.69k]
2210
8.01k
            ;
2211
6.69k
        else if (PyType_IsSubtype(candidate, winner)) {
  Branch (2211:18): [True: 6.69k, False: 3]
2212
6.69k
            winner = candidate;
2213
6.69k
            base = base_i;
2214
6.69k
        }
2215
3
        else {
2216
3
            PyErr_SetString(
2217
3
                PyExc_TypeError,
2218
3
                "multiple bases have "
2219
3
                "instance lay-out conflict");
2220
3
            return NULL;
2221
3
        }
2222
79.3k
    }
2223
64.6k
    assert (base != NULL);
2224
2225
64.6k
    return base;
2226
64.6k
}
2227
2228
static int
2229
extra_ivars(PyTypeObject *type, PyTypeObject *base)
2230
492k
{
2231
492k
    size_t t_size = type->tp_basicsize;
2232
492k
    size_t b_size = base->tp_basicsize;
2233
2234
492k
    assert(t_size >= b_size); /* Else type smaller than base! */
2235
492k
    if (type->tp_itemsize || base->tp_itemsize) {
  Branch (2235:9): [True: 20.5k, False: 471k]
  Branch (2235:30): [True: 0, False: 471k]
2236
        /* If itemsize is involved, stricter rules */
2237
20.5k
        return t_size != b_size ||
  Branch (2237:16): [True: 16.8k, False: 3.67k]
2238
20.5k
            type->tp_itemsize != base->tp_itemsize;
  Branch (2238:13): [True: 0, False: 3.67k]
2239
20.5k
    }
2240
471k
    if (type->tp_weaklistoffset && base->tp_weaklistoffset == 0 &&
  Branch (2240:9): [True: 132k, False: 339k]
  Branch (2240:36): [True: 126k, False: 6.08k]
2241
471k
        type->tp_weaklistoffset + sizeof(PyObject *) == t_size &&
  Branch (2241:9): [True: 125k, False: 403]
2242
471k
        type->tp_flags & Py_TPFLAGS_HEAPTYPE)
Line
Count
Source
375
125k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (2242:9): [True: 118k, False: 7.66k]
2243
118k
        t_size -= sizeof(PyObject *);
2244
471k
    return t_size != b_size;
2245
492k
}
2246
2247
static PyTypeObject *
2248
solid_base(PyTypeObject *type)
2249
492k
{
2250
492k
    PyTypeObject *base;
2251
2252
492k
    if (type->tp_base)
  Branch (2252:9): [True: 311k, False: 180k]
2253
311k
        base = solid_base(type->tp_base);
2254
180k
    else
2255
180k
        base = &PyBaseObject_Type;
2256
492k
    if (extra_ivars(type, base))
  Branch (2256:9): [True: 71.9k, False: 420k]
2257
71.9k
        return type;
2258
420k
    else
2259
420k
        return base;
2260
492k
}
2261
2262
static void object_dealloc(PyObject *);
2263
static PyObject *object_new(PyTypeObject *, PyObject *, PyObject *);
2264
static int object_init(PyObject *, PyObject *, PyObject *);
2265
static int update_slot(PyTypeObject *, PyObject *);
2266
static void fixup_slot_dispatchers(PyTypeObject *);
2267
static int type_new_set_names(PyTypeObject *);
2268
static int type_new_init_subclass(PyTypeObject *, PyObject *);
2269
2270
/*
2271
 * Helpers for  __dict__ descriptor.  We don't want to expose the dicts
2272
 * inherited from various builtin types.  The builtin base usually provides
2273
 * its own __dict__ descriptor, so we use that when we can.
2274
 */
2275
static PyTypeObject *
2276
get_builtin_base_with_dict(PyTypeObject *type)
2277
414k
{
2278
1.76M
    while (type->tp_base != NULL) {
  Branch (2278:12): [True: 1.35M, False: 414k]
2279
1.35M
        if (type->tp_dictoffset != 0 &&
  Branch (2279:13): [True: 1.33M, False: 16.7k]
2280
1.35M
            !(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
Line
Count
Source
375
1.33M
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (2280:13): [True: 12, False: 1.33M]
2281
12
            return type;
2282
1.35M
        type = type->tp_base;
2283
1.35M
    }
2284
414k
    return NULL;
2285
414k
}
2286
2287
static PyObject *
2288
get_dict_descriptor(PyTypeObject *type)
2289
12
{
2290
12
    PyObject *descr;
2291
2292
12
    descr = _PyType_Lookup(type, &_Py_ID(__dict__));
Line
Count
Source
374
12
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
12
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
12
    _PyRuntime.global_objects.NAME
2293
12
    if (descr == NULL || !PyDescr_IsData(descr))
  Branch (2293:9): [True: 0, False: 12]
  Branch (2293:26): [True: 0, False: 12]
2294
0
        return NULL;
2295
2296
12
    return descr;
2297
12
}
2298
2299
static void
2300
raise_dict_descr_error(PyObject *obj)
2301
0
{
2302
0
    PyErr_Format(PyExc_TypeError,
2303
0
                 "this __dict__ descriptor does not support "
2304
0
                 "'%.200s' objects", Py_TYPE(obj)->tp_name);
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
2305
0
}
2306
2307
static PyObject *
2308
subtype_dict(PyObject *obj, void *context)
2309
413k
{
2310
413k
    PyTypeObject *base;
2311
2312
413k
    base = get_builtin_base_with_dict(Py_TYPE(obj));
Line
Count
Source
138
413k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
413k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
413k
#  define _Py_CAST(type, expr) ((type)(expr))
2313
413k
    if (base != NULL) {
  Branch (2313:9): [True: 2, False: 413k]
2314
2
        descrgetfunc func;
2315
2
        PyObject *descr = get_dict_descriptor(base);
2316
2
        if (descr == NULL) {
  Branch (2316:13): [True: 0, False: 2]
2317
0
            raise_dict_descr_error(obj);
2318
0
            return NULL;
2319
0
        }
2320
2
        func = Py_TYPE(descr)->tp_descr_get;
Line
Count
Source
138
2
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
2321
2
        if (func == NULL) {
  Branch (2321:13): [True: 0, False: 2]
2322
0
            raise_dict_descr_error(obj);
2323
0
            return NULL;
2324
0
        }
2325
2
        return func(descr, obj, (PyObject *)(Py_TYPE(obj)));
Line
Count
Source
138
2
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
2326
2
    }
2327
413k
    return PyObject_GenericGetDict(obj, context);
2328
413k
}
2329
2330
static int
2331
subtype_setdict(PyObject *obj, PyObject *value, void *context)
2332
592
{
2333
592
    PyObject **dictptr;
2334
592
    PyTypeObject *base;
2335
2336
592
    base = get_builtin_base_with_dict(Py_TYPE(obj));
Line
Count
Source
138
592
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
592
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
592
#  define _Py_CAST(type, expr) ((type)(expr))
2337
592
    if (base != NULL) {
  Branch (2337:9): [True: 10, False: 582]
2338
10
        descrsetfunc func;
2339
10
        PyObject *descr = get_dict_descriptor(base);
2340
10
        if (descr == NULL) {
  Branch (2340:13): [True: 0, False: 10]
2341
0
            raise_dict_descr_error(obj);
2342
0
            return -1;
2343
0
        }
2344
10
        func = Py_TYPE(descr)->tp_descr_set;
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
2345
10
        if (func == NULL) {
  Branch (2345:13): [True: 0, False: 10]
2346
0
            raise_dict_descr_error(obj);
2347
0
            return -1;
2348
0
        }
2349
10
        return func(descr, obj, value);
2350
10
    }
2351
    /* Almost like PyObject_GenericSetDict, but allow __dict__ to be deleted. */
2352
582
    dictptr = _PyObject_GetDictPtr(obj);
2353
582
    if (dictptr == NULL) {
  Branch (2353:9): [True: 0, False: 582]
2354
0
        PyErr_SetString(PyExc_AttributeError,
2355
0
                        "This object has no __dict__");
2356
0
        return -1;
2357
0
    }
2358
582
    if (value != NULL && !PyDict_Check(value)) {
Line
Count
Source
18
581
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
Line
Count
Source
782
581
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (2358:9): [True: 581, False: 1]
  Branch (2358:26): [True: 3, False: 578]
2359
3
        PyErr_Format(PyExc_TypeError,
2360
3
                     "__dict__ must be set to a dictionary, "
2361
3
                     "not a '%.200s'", Py_TYPE(value)->tp_name);
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
2362
3
        return -1;
2363
3
    }
2364
579
    Py_XINCREF(value);
Line
Count
Source
603
579
#  define Py_XINCREF(op) Py_XINCREF(_PyObject_CAST(op))
Line
Count
Source
109
579
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
579
#  define _Py_CAST(type, expr) ((type)(expr))
2365
579
    Py_XSETREF(*dictptr, value);
Line
Count
Source
339
579
    do {                                        \
340
579
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
579
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
579
#  define _Py_CAST(type, expr) ((type)(expr))
341
579
        (op) = (op2);                           \
342
579
        Py_XDECREF(_py_tmp);                    \
Line
Count
Source
613
579
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
579
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
579
#  define _Py_CAST(type, expr) ((type)(expr))
343
579
    } while (0)
  Branch (343:14): [Folded - Ignored]
2366
579
    return 0;
2367
582
}
2368
2369
static PyObject *
2370
subtype_getweakref(PyObject *obj, void *context)
2371
76
{
2372
76
    PyObject **weaklistptr;
2373
76
    PyObject *result;
2374
76
    PyTypeObject *type = Py_TYPE(obj);
Line
Count
Source
138
76
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
76
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
76
#  define _Py_CAST(type, expr) ((type)(expr))
2375
2376
76
    if (type->tp_weaklistoffset == 0) {
  Branch (2376:9): [True: 0, False: 76]
2377
0
        PyErr_SetString(PyExc_AttributeError,
2378
0
                        "This object has no __weakref__");
2379
0
        return NULL;
2380
0
    }
2381
76
    _PyObject_ASSERT((PyObject *)type,
Line
Count
Source
390
76
    _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
Line
Count
Source
388
76
    _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
Line
Count
Source
377
76
    ((void)0)
2382
76
                     type->tp_weaklistoffset > 0);
2383
76
    _PyObject_ASSERT((PyObject *)type,
Line
Count
Source
390
76
    _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
Line
Count
Source
388
76
    _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
Line
Count
Source
377
76
    ((void)0)
2384
76
                     ((type->tp_weaklistoffset + sizeof(PyObject *))
2385
76
                      <= (size_t)(type->tp_basicsize)));
2386
76
    weaklistptr = (PyObject **)((char *)obj + type->tp_weaklistoffset);
2387
76
    if (*weaklistptr == NULL)
  Branch (2387:9): [True: 76, False: 0]
2388
76
        result = Py_None;
Line
Count
Source
654
76
#define Py_None (&_Py_NoneStruct)
2389
0
    else
2390
0
        result = *weaklistptr;
2391
76
    Py_INCREF(result);
Line
Count
Source
512
76
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
76
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
76
#  define _Py_CAST(type, expr) ((type)(expr))
2392
76
    return result;
2393
76
}
2394
2395
/* Three variants on the subtype_getsets list. */
2396
2397
static PyGetSetDef subtype_getsets_full[] = {
2398
    {"__dict__", subtype_dict, subtype_setdict,
2399
     PyDoc_STR("dictionary for instance variables (if defined)")},
2400
    {"__weakref__", subtype_getweakref, NULL,
2401
     PyDoc_STR("list of weak references to the object (if defined)")},
2402
    {0}
2403
};
2404
2405
static PyGetSetDef subtype_getsets_dict_only[] = {
2406
    {"__dict__", subtype_dict, subtype_setdict,
2407
     PyDoc_STR("dictionary for instance variables (if defined)")},
2408
    {0}
2409
};
2410
2411
static PyGetSetDef subtype_getsets_weakref_only[] = {
2412
    {"__weakref__", subtype_getweakref, NULL,
2413
     PyDoc_STR("list of weak references to the object (if defined)")},
2414
    {0}
2415
};
2416
2417
static int
2418
valid_identifier(PyObject *s)
2419
3.02k
{
2420
3.02k
    if (!PyUnicode_Check(s)) {
Line
Count
Source
115
3.02k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
3.02k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (2420:9): [True: 3, False: 3.02k]
2421
3
        PyErr_Format(PyExc_TypeError,
2422
3
                     "__slots__ items must be strings, not '%.200s'",
2423
3
                     Py_TYPE(s)->tp_name);
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
2424
3
        return 0;
2425
3
    }
2426
3.02k
    if (!PyUnicode_IsIdentifier(s)) {
  Branch (2426:9): [True: 8, False: 3.01k]
2427
8
        PyErr_SetString(PyExc_TypeError,
2428
8
                        "__slots__ must be identifiers");
2429
8
        return 0;
2430
8
    }
2431
3.01k
    return 1;
2432
3.02k
}
2433
2434
static int
2435
type_init(PyObject *cls, PyObject *args, PyObject *kwds)
2436
86.0k
{
2437
86.0k
    assert(args != NULL && PyTuple_Check(args));
2438
86.0k
    assert(kwds == NULL || PyDict_Check(kwds));
2439
2440
86.0k
    if (kwds != NULL && PyTuple_GET_SIZE(args) == 1 &&
Line
Count
Source
26
3.32k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
3.32k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.32k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (2440:9): [True: 3.32k, False: 82.7k]
  Branch (2440:25): [True: 0, False: 3.32k]
2441
86.0k
        PyDict_GET_SIZE(kwds) != 0) {
Line
Count
Source
55
0
#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (2441:9): [True: 0, False: 0]
2442
0
        PyErr_SetString(PyExc_TypeError,
2443
0
                        "type.__init__() takes no keyword arguments");
2444
0
        return -1;
2445
0
    }
2446
2447
86.0k
    if ((PyTuple_GET_SIZE(args) != 1 && PyTuple_GET_SIZE(args) != 3)) {
Line
Count
Source
26
86.0k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
86.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.0k
#  define _Py_CAST(type, expr) ((type)(expr))
    if ((PyTuple_GET_SIZE(args) != 1 && PyTuple_GET_SIZE(args) != 3)) {
Line
Count
Source
26
86.0k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
86.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.0k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (2447:10): [True: 86.0k, False: 0]
  Branch (2447:41): [True: 0, False: 86.0k]
2448
0
        PyErr_SetString(PyExc_TypeError,
2449
0
                        "type.__init__() takes 1 or 3 arguments");
2450
0
        return -1;
2451
0
    }
2452
2453
86.0k
    return 0;
2454
86.0k
}
2455
2456
2457
unsigned long
2458
PyType_GetFlags(PyTypeObject *type)
2459
8
{
2460
8
    return type->tp_flags;
2461
8
}
2462
2463
2464
int
2465
PyType_SUPPORTS_WEAKREFS(PyTypeObject *type)
2466
0
{
2467
0
    return _PyType_SUPPORTS_WEAKREFS(type);
2468
0
}
2469
2470
2471
/* Determine the most derived metatype. */
2472
PyTypeObject *
2473
_PyType_CalculateMetaclass(PyTypeObject *metatype, PyObject *bases)
2474
129k
{
2475
129k
    Py_ssize_t i, nbases;
2476
129k
    PyTypeObject *winner;
2477
129k
    PyObject *tmp;
2478
129k
    PyTypeObject *tmptype;
2479
2480
    /* Determine the proper metatype to deal with this,
2481
       and check for metatype conflicts while we're at it.
2482
       Note that if some other metatype wins to contract,
2483
       it's possible that its instances are not types. */
2484
2485
129k
    nbases = PyTuple_GET_SIZE(bases);
Line
Count
Source
26
129k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
129k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
129k
#  define _Py_CAST(type, expr) ((type)(expr))
2486
129k
    winner = metatype;
2487
253k
    for (i = 0; i < nbases; i++) {
  Branch (2487:17): [True: 124k, False: 129k]
2488
124k
        tmp = PyTuple_GET_ITEM(bases, i);
Line
Count
Source
28
124k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
124k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
124k
#  define _Py_CAST(type, expr) ((type)(expr))
2489
124k
        tmptype = Py_TYPE(tmp);
Line
Count
Source
138
124k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
124k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
124k
#  define _Py_CAST(type, expr) ((type)(expr))
2490
124k
        if (PyType_IsSubtype(winner, tmptype))
  Branch (2490:13): [True: 122k, False: 1.78k]
2491
122k
            continue;
2492
1.78k
        if (PyType_IsSubtype(tmptype, winner)) {
  Branch (2492:13): [True: 1.78k, False: 7]
2493
1.78k
            winner = tmptype;
2494
1.78k
            continue;
2495
1.78k
        }
2496
        /* else: */
2497
7
        PyErr_SetString(PyExc_TypeError,
2498
7
                        "metaclass conflict: "
2499
7
                        "the metaclass of a derived class "
2500
7
                        "must be a (non-strict) subclass "
2501
7
                        "of the metaclasses of all its bases");
2502
7
        return NULL;
2503
1.78k
    }
2504
129k
    return winner;
2505
129k
}
2506
2507
2508
// Forward declaration
2509
static PyObject *
2510
type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds);
2511
2512
typedef struct {
2513
    PyTypeObject *metatype;
2514
    PyObject *args;
2515
    PyObject *kwds;
2516
    PyObject *orig_dict;
2517
    PyObject *name;
2518
    PyObject *bases;
2519
    PyTypeObject *base;
2520
    PyObject *slots;
2521
    Py_ssize_t nslot;
2522
    int add_dict;
2523
    int add_weak;
2524
    int may_add_dict;
2525
    int may_add_weak;
2526
} type_new_ctx;
2527
2528
2529
/* Check for valid slot names and two special cases */
2530
static int
2531
type_new_visit_slots(type_new_ctx *ctx)
2532
9.04k
{
2533
9.04k
    PyObject *slots = ctx->slots;
2534
9.04k
    Py_ssize_t nslot = ctx->nslot;
2535
12.0k
    for (Py_ssize_t i = 0; i < nslot; i++) {
  Branch (2535:28): [True: 3.02k, False: 9.03k]
2536
3.02k
        PyObject *name = PyTuple_GET_ITEM(slots, i);
Line
Count
Source
28
3.02k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
3.02k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
3.02k
#  define _Py_CAST(type, expr) ((type)(expr))
2537
3.02k
        if (!valid_identifier(name)) {
  Branch (2537:13): [True: 11, False: 3.01k]
2538
11
            return -1;
2539
11
        }
2540
3.01k
        assert(PyUnicode_Check(name));
2541
3.01k
        if (_PyUnicode_Equal(name, &_Py_ID(__dict__))) {
Line
Count
Source
374
3.01k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
3.01k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
3.01k
    _PyRuntime.global_objects.NAME
  Branch (2541:13): [True: 104, False: 2.91k]
2542
104
            if (!ctx->may_add_dict || ctx->add_dict != 0) {
  Branch (2542:17): [True: 1, False: 103]
  Branch (2542:39): [True: 1, False: 102]
2543
2
                PyErr_SetString(PyExc_TypeError,
2544
2
                    "__dict__ slot disallowed: "
2545
2
                    "we already got one");
2546
2
                return -1;
2547
2
            }
2548
102
            ctx->add_dict++;
2549
102
        }
2550
3.01k
        if (_PyUnicode_Equal(name, &_Py_ID(__weakref__))) {
Line
Count
Source
374
3.01k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
3.01k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
3.01k
    _PyRuntime.global_objects.NAME
  Branch (2550:13): [True: 233, False: 2.77k]
2551
233
            if (!ctx->may_add_weak || ctx->add_weak != 0) {
  Branch (2551:17): [True: 1, False: 232]
  Branch (2551:39): [True: 1, False: 231]
2552
2
                PyErr_SetString(PyExc_TypeError,
2553
2
                    "__weakref__ slot disallowed: "
2554
2
                    "either we already got one, "
2555
2
                    "or __itemsize__ != 0");
2556
2
                return -1;
2557
2
            }
2558
231
            ctx->add_weak++;
2559
231
        }
2560
3.01k
    }
2561
9.03k
    return 0;
2562
9.04k
}
2563
2564
2565
/* Copy slots into a list, mangle names and sort them.
2566
   Sorted names are needed for __class__ assignment.
2567
   Convert them back to tuple at the end.
2568
*/
2569
static PyObject*
2570
type_new_copy_slots(type_new_ctx *ctx, PyObject *dict)
2571
9.03k
{
2572
9.03k
    PyObject *slots = ctx->slots;
2573
9.03k
    Py_ssize_t nslot = ctx->nslot;
2574
2575
9.03k
    Py_ssize_t new_nslot = nslot - ctx->add_dict - ctx->add_weak;
2576
9.03k
    PyObject *new_slots = PyList_New(new_nslot);
2577
9.03k
    if (new_slots == NULL) {
  Branch (2577:9): [True: 0, False: 9.03k]
2578
0
        return NULL;
2579
0
    }
2580
2581
9.03k
    Py_ssize_t j = 0;
2582
12.0k
    for (Py_ssize_t i = 0; i < nslot; i++) {
  Branch (2582:28): [True: 3.00k, False: 9.03k]
2583
3.00k
        PyObject *slot = PyTuple_GET_ITEM(slots, i);
Line
Count
Source
28
3.00k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
3.00k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
3.00k
#  define _Py_CAST(type, expr) ((type)(expr))
2584
3.00k
        if ((ctx->add_dict && _PyUnicode_Equal(slot, &_Py_ID(__dict__))) ||
Line
Count
Source
374
476
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
476
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
476
    _PyRuntime.global_objects.NAME
  Branch (2584:14): [True: 476, False: 2.53k]
  Branch (2584:31): [True: 101, False: 375]
2585
3.00k
            (ctx->add_weak && _PyUnicode_Equal(slot, &_Py_ID(__weakref__))))
Line
Count
Source
374
858
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
858
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
858
    _PyRuntime.global_objects.NAME
  Branch (2585:14): [True: 858, False: 2.04k]
  Branch (2585:31): [True: 230, False: 628]
2586
331
        {
2587
331
            continue;
2588
331
        }
2589
2590
2.67k
        slot =_Py_Mangle(ctx->name, slot);
2591
2.67k
        if (!slot) {
  Branch (2591:13): [True: 0, False: 2.67k]
2592
0
            goto error;
2593
0
        }
2594
2.67k
        PyList_SET_ITEM(new_slots, j, slot);
Line
Count
Source
47
2.67k
    PyList_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
2.67k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.67k
#  define _Py_CAST(type, expr) ((type)(expr))
    PyList_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
2.67k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.67k
#  define _Py_CAST(type, expr) ((type)(expr))
2595
2596
2.67k
        int r = PyDict_Contains(dict, slot);
2597
2.67k
        if (r < 0) {
  Branch (2597:13): [True: 0, False: 2.67k]
2598
0
            goto error;
2599
0
        }
2600
2.67k
        if (r > 0) {
  Branch (2600:13): [True: 6, False: 2.67k]
2601
            /* CPython inserts __qualname__ and __classcell__ (when needed)
2602
               into the namespace when creating a class.  They will be deleted
2603
               below so won't act as class variables. */
2604
6
            if (!_PyUnicode_Equal(slot, &_Py_ID(__qualname__)) &&
Line
Count
Source
374
6
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
6
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
6
    _PyRuntime.global_objects.NAME
  Branch (2604:17): [True: 4, False: 2]
2605
6
                !_PyUnicode_Equal(slot, &_Py_ID(__classcell__)))
Line
Count
Source
374
4
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
4
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
4
    _PyRuntime.global_objects.NAME
  Branch (2605:17): [True: 2, False: 2]
2606
2
            {
2607
2
                PyErr_Format(PyExc_ValueError,
2608
2
                             "%R in __slots__ conflicts with class variable",
2609
2
                             slot);
2610
2
                goto error;
2611
2
            }
2612
6
        }
2613
2614
2.67k
        j++;
2615
2.67k
    }
2616
9.03k
    assert(j == new_nslot);
2617
2618
9.03k
    if (PyList_Sort(new_slots) == -1) {
  Branch (2618:9): [True: 0, False: 9.03k]
2619
0
        goto error;
2620
0
    }
2621
2622
9.03k
    PyObject *tuple = PyList_AsTuple(new_slots);
2623
9.03k
    Py_DECREF(new_slots);
Line
Count
Source
548
9.03k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
9.03k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.03k
#  define _Py_CAST(type, expr) ((type)(expr))
2624
9.03k
    if (tuple == NULL) {
  Branch (2624:9): [True: 0, False: 9.03k]
2625
0
        return NULL;
2626
0
    }
2627
2628
9.03k
    assert(PyTuple_GET_SIZE(tuple) == new_nslot);
2629
9.03k
    return tuple;
2630
2631
2
error:
2632
2
    Py_DECREF(new_slots);
Line
Count
Source
548
2
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
2633
2
    return NULL;
2634
9.03k
}
2635
2636
2637
static void
2638
type_new_slots_bases(type_new_ctx *ctx)
2639
9.03k
{
2640
9.03k
    Py_ssize_t nbases = PyTuple_GET_SIZE(ctx->bases);
Line
Count
Source
26
9.03k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
9.03k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.03k
#  define _Py_CAST(type, expr) ((type)(expr))
2641
9.03k
    if (nbases > 1 &&
  Branch (2641:9): [True: 1.41k, False: 7.61k]
2642
9.03k
        ((ctx->may_add_dict && ctx->add_dict == 0) ||
  Branch (2642:11): [True: 1.41k, False: 2]
  Branch (2642:32): [True: 1.41k, False: 0]
2643
1.41k
         (ctx->may_add_weak && ctx->add_weak == 0)))
  Branch (2643:11): [True: 1, False: 1]
  Branch (2643:32): [True: 1, False: 0]
2644
1.41k
    {
2645
4.51k
        for (Py_ssize_t i = 0; i < nbases; i++) {
  Branch (2645:32): [True: 3.10k, False: 1.40k]
2646
3.10k
            PyObject *obj = PyTuple_GET_ITEM(ctx->bases, i);
Line
Count
Source
28
3.10k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
3.10k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
3.10k
#  define _Py_CAST(type, expr) ((type)(expr))
2647
3.10k
            if (obj == (PyObject *)ctx->base) {
  Branch (2647:17): [True: 1.41k, False: 1.69k]
2648
                /* Skip primary base */
2649
1.41k
                continue;
2650
1.41k
            }
2651
1.69k
            PyTypeObject *base = _PyType_CAST(obj);
Line
Count
Source
792
1.69k
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
1.69k
#  define _Py_CAST(type, expr) ((type)(expr))
2652
2653
1.69k
            if (ctx->may_add_dict && ctx->add_dict == 0 &&
  Branch (2653:17): [True: 1.69k, False: 1]
  Branch (2653:38): [True: 1.69k, False: 0]
2654
1.69k
                base->tp_dictoffset != 0)
  Branch (2654:17): [True: 4, False: 1.68k]
2655
4
            {
2656
4
                ctx->add_dict++;
2657
4
            }
2658
1.69k
            if (ctx->may_add_weak && ctx->add_weak == 0 &&
  Branch (2658:17): [True: 1.67k, False: 12]
  Branch (2658:38): [True: 1.67k, False: 2]
2659
1.69k
                base->tp_weaklistoffset != 0)
  Branch (2659:17): [True: 4, False: 1.67k]
2660
4
            {
2661
4
                ctx->add_weak++;
2662
4
            }
2663
1.69k
            if (ctx->may_add_dict && ctx->add_dict == 0) {
  Branch (2663:17): [True: 1.69k, False: 1]
  Branch (2663:38): [True: 1.68k, False: 4]
2664
1.68k
                continue;
2665
1.68k
            }
2666
5
            if (ctx->may_add_weak && ctx->add_weak == 0) {
  Branch (2666:17): [True: 4, False: 1]
  Branch (2666:38): [True: 0, False: 4]
2667
0
                continue;
2668
0
            }
2669
            /* Nothing more to check */
2670
5
            break;
2671
5
        }
2672
1.41k
    }
2673
9.03k
}
2674
2675
2676
static int
2677
type_new_slots_impl(type_new_ctx *ctx, PyObject *dict)
2678
9.05k
{
2679
    /* Are slots allowed? */
2680
9.05k
    if (ctx->nslot > 0 && ctx->base->tp_itemsize != 0) {
  Branch (2680:9): [True: 1.21k, False: 7.83k]
  Branch (2680:27): [True: 1, False: 1.21k]
2681
1
        PyErr_Format(PyExc_TypeError,
2682
1
                     "nonempty __slots__ not supported for subtype of '%s'",
2683
1
                     ctx->base->tp_name);
2684
1
        return -1;
2685
1
    }
2686
2687
9.04k
    if (type_new_visit_slots(ctx) < 0) {
  Branch (2687:9): [True: 15, False: 9.03k]
2688
15
        return -1;
2689
15
    }
2690
2691
9.03k
    PyObject *new_slots = type_new_copy_slots(ctx, dict);
2692
9.03k
    if (new_slots == NULL) {
  Branch (2692:9): [True: 2, False: 9.03k]
2693
2
        return -1;
2694
2
    }
2695
9.03k
    assert(PyTuple_CheckExact(new_slots));
2696
2697
9.03k
    Py_XSETREF(ctx->slots, new_slots);
Line
Count
Source
339
9.03k
    do {                                        \
340
9.03k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
9.03k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.03k
#  define _Py_CAST(type, expr) ((type)(expr))
341
9.03k
        (op) = (op2);                           \
342
9.03k
        Py_XDECREF(_py_tmp);                    \
Line
Count
Source
613
9.03k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
9.03k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.03k
#  define _Py_CAST(type, expr) ((type)(expr))
343
9.03k
    } while (0)
  Branch (343:14): [Folded - Ignored]
2698
9.03k
    ctx->nslot = PyTuple_GET_SIZE(new_slots);
Line
Count
Source
26
9.03k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
9.03k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.03k
#  define _Py_CAST(type, expr) ((type)(expr))
2699
2700
    /* Secondary bases may provide weakrefs or dict */
2701
9.03k
    type_new_slots_bases(ctx);
2702
9.03k
    return 0;
2703
9.03k
}
2704
2705
2706
static Py_ssize_t
2707
type_new_slots(type_new_ctx *ctx, PyObject *dict)
2708
86.7k
{
2709
    // Check for a __slots__ sequence variable in dict, and count it
2710
86.7k
    ctx->add_dict = 0;
2711
86.7k
    ctx->add_weak = 0;
2712
86.7k
    ctx->may_add_dict = (ctx->base->tp_dictoffset == 0);
2713
86.7k
    ctx->may_add_weak = (ctx->base->tp_weaklistoffset == 0
  Branch (2713:26): [True: 47.9k, False: 38.8k]
2714
86.7k
                         && ctx->base->tp_itemsize == 0);
  Branch (2714:29): [True: 45.4k, False: 2.51k]
2715
2716
86.7k
    if (ctx->slots == NULL) {
  Branch (2716:9): [True: 77.7k, False: 9.05k]
2717
77.7k
        if (ctx->may_add_dict) {
  Branch (2717:13): [True: 34.8k, False: 42.8k]
2718
34.8k
            ctx->add_dict++;
2719
34.8k
        }
2720
77.7k
        if (ctx->may_add_weak) {
  Branch (2720:13): [True: 37.1k, False: 40.5k]
2721
37.1k
            ctx->add_weak++;
2722
37.1k
        }
2723
77.7k
    }
2724
9.05k
    else {
2725
        /* Have slots */
2726
9.05k
        if (type_new_slots_impl(ctx, dict) < 0) {
  Branch (2726:13): [True: 18, False: 9.03k]
2727
18
            return -1;
2728
18
        }
2729
9.05k
    }
2730
86.7k
    return 0;
2731
86.7k
}
2732
2733
2734
static PyTypeObject*
2735
type_new_alloc(type_new_ctx *ctx)
2736
86.7k
{
2737
86.7k
    PyTypeObject *metatype = ctx->metatype;
2738
86.7k
    PyTypeObject *type;
2739
2740
    // Allocate the type object
2741
86.7k
    type = (PyTypeObject *)metatype->tp_alloc(metatype, ctx->nslot);
2742
86.7k
    if (type == NULL) {
  Branch (2742:9): [True: 0, False: 86.7k]
2743
0
        return NULL;
2744
0
    }
2745
86.7k
    PyHeapTypeObject *et = (PyHeapTypeObject *)type;
2746
2747
    // Initialize tp_flags.
2748
    // All heap types need GC, since we can create a reference cycle by storing
2749
    // an instance on one of its parents.
2750
86.7k
    type->tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE |
Line
Count
Source
427
86.7k
#define Py_TPFLAGS_DEFAULT  ( \
428
86.7k
                 Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
Line
Count
Source
400
86.7k
#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
429
86.7k
                0)
    type->tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE |
Line
Count
Source
375
86.7k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
2751
86.7k
                      Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC);
Line
Count
Source
378
86.7k
#define Py_TPFLAGS_BASETYPE (1UL << 10)
                      Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC);
Line
Count
Source
394
86.7k
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
2752
2753
    // Initialize essential fields
2754
86.7k
    type->tp_as_async = &et->as_async;
2755
86.7k
    type->tp_as_number = &et->as_number;
2756
86.7k
    type->tp_as_sequence = &et->as_sequence;
2757
86.7k
    type->tp_as_mapping = &et->as_mapping;
2758
86.7k
    type->tp_as_buffer = &et->as_buffer;
2759
2760
86.7k
    type->tp_bases = Py_NewRef(ctx->bases);
Line
Count
Source
639
86.7k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
86.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.7k
#  define _Py_CAST(type, expr) ((type)(expr))
2761
86.7k
    type->tp_base = (PyTypeObject *)Py_NewRef(ctx->base);
Line
Count
Source
639
86.7k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
86.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.7k
#  define _Py_CAST(type, expr) ((type)(expr))
2762
2763
86.7k
    type->tp_dealloc = subtype_dealloc;
2764
    /* Always override allocation strategy to use regular heap */
2765
86.7k
    type->tp_alloc = PyType_GenericAlloc;
2766
86.7k
    type->tp_free = PyObject_GC_Del;
2767
2768
86.7k
    type->tp_traverse = subtype_traverse;
2769
86.7k
    type->tp_clear = subtype_clear;
2770
2771
86.7k
    et->ht_name = Py_NewRef(ctx->name);
Line
Count
Source
639
86.7k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
86.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.7k
#  define _Py_CAST(type, expr) ((type)(expr))
2772
86.7k
    et->ht_module = NULL;
2773
86.7k
    et->_ht_tpname = NULL;
2774
2775
86.7k
    return type;
2776
86.7k
}
2777
2778
2779
static int
2780
type_new_set_name(const type_new_ctx *ctx, PyTypeObject *type)
2781
86.7k
{
2782
86.7k
    Py_ssize_t name_size;
2783
86.7k
    type->tp_name = PyUnicode_AsUTF8AndSize(ctx->name, &name_size);
2784
86.7k
    if (!type->tp_name) {
  Branch (2784:9): [True: 1, False: 86.7k]
2785
1
        return -1;
2786
1
    }
2787
86.7k
    if (strlen(type->tp_name) != (size_t)name_size) {
  Branch (2787:9): [True: 1, False: 86.7k]
2788
1
        PyErr_SetString(PyExc_ValueError,
2789
1
                        "type name must not contain null characters");
2790
1
        return -1;
2791
1
    }
2792
86.7k
    return 0;
2793
86.7k
}
2794
2795
2796
/* Set __module__ in the dict */
2797
static int
2798
type_new_set_module(PyTypeObject *type)
2799
86.7k
{
2800
86.7k
    int r = PyDict_Contains(type->tp_dict, &_Py_ID(__module__));
Line
Count
Source
374
86.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
86.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
86.7k
    _PyRuntime.global_objects.NAME
2801
86.7k
    if (r < 0) {
  Branch (2801:9): [True: 0, False: 86.7k]
2802
0
        return -1;
2803
0
    }
2804
86.7k
    if (r > 0) {
  Branch (2804:9): [True: 68.0k, False: 18.7k]
2805
68.0k
        return 0;
2806
68.0k
    }
2807
2808
18.7k
    PyObject *globals = PyEval_GetGlobals();
2809
18.7k
    if (globals == NULL) {
  Branch (2809:9): [True: 0, False: 18.7k]
2810
0
        return 0;
2811
0
    }
2812
2813
18.7k
    PyObject *module = PyDict_GetItemWithError(globals, &_Py_ID(__name__));
Line
Count
Source
374
18.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
18.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
18.7k
    _PyRuntime.global_objects.NAME
2814
18.7k
    if (module == NULL) {
  Branch (2814:9): [True: 0, False: 18.7k]
2815
0
        if (PyErr_Occurred()) {
  Branch (2815:13): [True: 0, False: 0]
2816
0
            return -1;
2817
0
        }
2818
0
        return 0;
2819
0
    }
2820
2821
18.7k
    if (PyDict_SetItem(type->tp_dict, &_Py_ID(__module__), module) < 0) {
Line
Count
Source
374
18.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
18.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
18.7k
    _PyRuntime.global_objects.NAME
  Branch (2821:9): [True: 0, False: 18.7k]
2822
0
        return -1;
2823
0
    }
2824
18.7k
    return 0;
2825
18.7k
}
2826
2827
2828
/* Set ht_qualname to dict['__qualname__'] if available, else to
2829
   __name__.  The __qualname__ accessor will look for ht_qualname. */
2830
static int
2831
type_new_set_ht_name(PyTypeObject *type)
2832
86.7k
{
2833
86.7k
    PyHeapTypeObject *et = (PyHeapTypeObject *)type;
2834
86.7k
    PyObject *qualname = PyDict_GetItemWithError(
2835
86.7k
            type->tp_dict, &_Py_ID(__qualname__));
Line
Count
Source
374
86.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
86.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
86.7k
    _PyRuntime.global_objects.NAME
2836
86.7k
    if (qualname != NULL) {
  Branch (2836:9): [True: 64.8k, False: 21.8k]
2837
64.8k
        if (!PyUnicode_Check(qualname)) {
Line
Count
Source
115
64.8k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
64.8k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (2837:13): [True: 3, False: 64.8k]
2838
3
            PyErr_Format(PyExc_TypeError,
2839
3
                    "type __qualname__ must be a str, not %s",
2840
3
                    Py_TYPE(qualname)->tp_name);
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
2841
3
            return -1;
2842
3
        }
2843
64.8k
        et->ht_qualname = Py_NewRef(qualname);
Line
Count
Source
639
64.8k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
64.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
64.8k
#  define _Py_CAST(type, expr) ((type)(expr))
2844
64.8k
        if (PyDict_DelItem(type->tp_dict, &_Py_ID(__qualname__)) < 0) {
Line
Count
Source
374
64.8k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
64.8k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
64.8k
    _PyRuntime.global_objects.NAME
  Branch (2844:13): [True: 0, False: 64.8k]
2845
0
            return -1;
2846
0
        }
2847
64.8k
    }
2848
21.8k
    else {
2849
21.8k
        if (PyErr_Occurred()) {
  Branch (2849:13): [True: 0, False: 21.8k]
2850
0
            return -1;
2851
0
        }
2852
21.8k
        et->ht_qualname = Py_NewRef(et->ht_name);
Line
Count
Source
639
21.8k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
21.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21.8k
#  define _Py_CAST(type, expr) ((type)(expr))
2853
21.8k
    }
2854
86.7k
    return 0;
2855
86.7k
}
2856
2857
2858
/* Set tp_doc to a copy of dict['__doc__'], if the latter is there
2859
   and is a string.  The __doc__ accessor will first look for tp_doc;
2860
   if that fails, it will still look into __dict__. */
2861
static int
2862
type_new_set_doc(PyTypeObject *type)
2863
86.7k
{
2864
86.7k
    PyObject *doc = PyDict_GetItemWithError(type->tp_dict, &_Py_ID(__doc__));
Line
Count
Source
374
86.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
86.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
86.7k
    _PyRuntime.global_objects.NAME
2865
86.7k
    if (doc == NULL) {
  Branch (2865:9): [True: 54.9k, False: 31.7k]
2866
54.9k
        if (PyErr_Occurred()) {
  Branch (2866:13): [True: 0, False: 54.9k]
2867
0
            return -1;
2868
0
        }
2869
        // no __doc__ key
2870
54.9k
        return 0;
2871
54.9k
    }
2872
31.7k
    if (!PyUnicode_Check(doc)) {
Line
Count
Source
115
31.7k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
31.7k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (2872:9): [True: 72, False: 31.7k]
2873
        // ignore non-string __doc__
2874
72
        return 0;
2875
72
    }
2876
2877
31.7k
    const char *doc_str = PyUnicode_AsUTF8(doc);
2878
31.7k
    if (doc_str == NULL) {
  Branch (2878:9): [True: 1, False: 31.7k]
2879
1
        return -1;
2880
1
    }
2881
2882
    // Silently truncate the docstring if it contains a null byte
2883
31.7k
    Py_ssize_t size = strlen(doc_str) + 1;
2884
31.7k
    char *tp_doc = (char *)PyObject_Malloc(size);
2885
31.7k
    if (tp_doc == NULL) {
  Branch (2885:9): [True: 0, False: 31.7k]
2886
0
        PyErr_NoMemory();
2887
0
        return -1;
2888
0
    }
2889
2890
31.7k
    memcpy(tp_doc, doc_str, size);
2891
31.7k
    type->tp_doc = tp_doc;
2892
31.7k
    return 0;
2893
31.7k
}
2894
2895
2896
static int
2897
type_new_staticmethod(PyTypeObject *type, PyObject *attr)
2898
86.7k
{
2899
86.7k
    PyObject *func = PyDict_GetItemWithError(type->tp_dict, attr);
2900
86.7k
    if (func == NULL) {
  Branch (2900:9): [True: 84.6k, False: 2.05k]
2901
84.6k
        if (PyErr_Occurred()) {
  Branch (2901:13): [True: 0, False: 84.6k]
2902
0
            return -1;
2903
0
        }
2904
84.6k
        return 0;
2905
84.6k
    }
2906
2.05k
    if (!PyFunction_Check(func)) {
Line
Count
Source
63
2.05k
#define PyFunction_Check(op) Py_IS_TYPE((op), &PyFunction_Type)
Line
Count
Source
155
2.05k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
2.05k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.05k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (2906:9): [True: 13, False: 2.04k]
2907
13
        return 0;
2908
13
    }
2909
2910
2.04k
    PyObject *static_func = PyStaticMethod_New(func);
2911
2.04k
    if (static_func == NULL) {
  Branch (2911:9): [True: 0, False: 2.04k]
2912
0
        return -1;
2913
0
    }
2914
2.04k
    if (PyDict_SetItem(type->tp_dict, attr, static_func) < 0) {
  Branch (2914:9): [True: 0, False: 2.04k]
2915
0
        Py_DECREF(static_func);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
2916
0
        return -1;
2917
0
    }
2918
2.04k
    Py_DECREF(static_func);
Line
Count
Source
548
2.04k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
2.04k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.04k
#  define _Py_CAST(type, expr) ((type)(expr))
2919
2.04k
    return 0;
2920
2.04k
}
2921
2922
2923
static int
2924
type_new_classmethod(PyTypeObject *type, PyObject *attr)
2925
173k
{
2926
173k
    PyObject *func = PyDict_GetItemWithError(type->tp_dict, attr);
2927
173k
    if (func == NULL) {
  Branch (2927:9): [True: 171k, False: 2.40k]
2928
171k
        if (PyErr_Occurred()) {
  Branch (2928:13): [True: 0, False: 171k]
2929
0
            return -1;
2930
0
        }
2931
171k
        return 0;
2932
171k
    }
2933
2.40k
    if (!PyFunction_Check(func)) {
Line
Count
Source
63
2.40k
#define PyFunction_Check(op) Py_IS_TYPE((op), &PyFunction_Type)
Line
Count
Source
155
2.40k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
2.40k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.40k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (2933:9): [True: 2.29k, False: 106]
2934
2.29k
        return 0;
2935
2.29k
    }
2936
2937
106
    PyObject *method = PyClassMethod_New(func);
2938
106
    if (method == NULL) {
  Branch (2938:9): [True: 0, False: 106]
2939
0
        return -1;
2940
0
    }
2941
2942
106
    if (PyDict_SetItem(type->tp_dict, attr, method) < 0) {
  Branch (2942:9): [True: 0, False: 106]
2943
0
        Py_DECREF(method);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
2944
0
        return -1;
2945
0
    }
2946
106
    Py_DECREF(method);
Line
Count
Source
548
106
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
106
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
106
#  define _Py_CAST(type, expr) ((type)(expr))
2947
106
    return 0;
2948
106
}
2949
2950
2951
/* Add descriptors for custom slots from __slots__, or for __dict__ */
2952
static int
2953
type_new_descriptors(const type_new_ctx *ctx, PyTypeObject *type)
2954
86.7k
{
2955
86.7k
    PyHeapTypeObject *et = (PyHeapTypeObject *)type;
2956
86.7k
    Py_ssize_t slotoffset = ctx->base->tp_basicsize;
2957
86.7k
    if (et->ht_slots != NULL) {
  Branch (2957:9): [True: 9.03k, False: 77.7k]
2958
9.03k
        PyMemberDef *mp = _PyHeapType_GET_MEMBERS(et);
Line
Count
Source
279
9.03k
    ((PyMemberDef *)(((char *)(etype)) + Py_TYPE(etype)->tp_basicsize))
Line
Count
Source
138
9.03k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
9.03k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.03k
#  define _Py_CAST(type, expr) ((type)(expr))
2959
9.03k
        Py_ssize_t nslot = PyTuple_GET_SIZE(et->ht_slots);
Line
Count
Source
26
9.03k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
9.03k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.03k
#  define _Py_CAST(type, expr) ((type)(expr))
2960
11.7k
        for (Py_ssize_t i = 0; i < nslot; i++, mp++) {
  Branch (2960:32): [True: 2.67k, False: 9.03k]
2961
2.67k
            mp->name = PyUnicode_AsUTF8(
2962
2.67k
                PyTuple_GET_ITEM(et->ht_slots, i));
Line
Count
Source
28
2.67k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
2.67k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
2.67k
#  define _Py_CAST(type, expr) ((type)(expr))
2963
2.67k
            if (mp->name == NULL) {
  Branch (2963:17): [True: 0, False: 2.67k]
2964
0
                return -1;
2965
0
            }
2966
2.67k
            mp->type = T_OBJECT_EX;
Line
Count
Source
49
2.67k
#define T_OBJECT_EX 16  /* Like T_OBJECT, but raises AttributeError
2967
2.67k
            mp->offset = slotoffset;
2968
2969
            /* __dict__ and __weakref__ are already filtered out */
2970
2.67k
            assert(strcmp(mp->name, "__dict__") != 0);
2971
2.67k
            assert(strcmp(mp->name, "__weakref__") != 0);
2972
2973
2.67k
            slotoffset += sizeof(PyObject *);
2974
2.67k
        }
2975
9.03k
    }
2976
2977
86.7k
    if (ctx->add_dict && ctx->base->tp_itemsize) {
  Branch (2977:9): [True: 34.9k, False: 51.7k]
  Branch (2977:26): [True: 812, False: 34.1k]
2978
812
        type->tp_dictoffset = -(long)sizeof(PyObject *);
2979
812
        slotoffset += sizeof(PyObject *);
2980
812
    }
2981
2982
86.7k
    if (ctx->add_weak) {
  Branch (2982:9): [True: 37.3k, False: 49.3k]
2983
37.3k
        assert(!ctx->base->tp_itemsize);
2984
37.3k
        type->tp_weaklistoffset = slotoffset;
2985
37.3k
        slotoffset += sizeof(PyObject *);
2986
37.3k
    }
2987
86.7k
    if (ctx->add_dict && ctx->base->tp_itemsize == 0) {
  Branch (2987:9): [True: 34.9k, False: 51.7k]
  Branch (2987:26): [True: 34.1k, False: 812]
2988
34.1k
        assert((type->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0);
2989
34.1k
        type->tp_flags |= Py_TPFLAGS_MANAGED_DICT;
Line
Count
Source
359
34.1k
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
2990
34.1k
        type->tp_dictoffset = -slotoffset - sizeof(PyObject *)*3;
2991
34.1k
    }
2992
2993
86.7k
    type->tp_basicsize = slotoffset;
2994
86.7k
    type->tp_itemsize = ctx->base->tp_itemsize;
2995
86.7k
    type->tp_members = _PyHeapType_GET_MEMBERS(et);
Line
Count
Source
279
86.7k
    ((PyMemberDef *)(((char *)(etype)) + Py_TYPE(etype)->tp_basicsize))
Line
Count
Source
138
86.7k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
86.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.7k
#  define _Py_CAST(type, expr) ((type)(expr))
2996
86.7k
    return 0;
2997
86.7k
}
2998
2999
3000
static void
3001
type_new_set_slots(const type_new_ctx *ctx, PyTypeObject *type)
3002
86.7k
{
3003
86.7k
    if (type->tp_weaklistoffset && type->tp_dictoffset) {
  Branch (3003:9): [True: 37.3k, False: 49.3k]
  Branch (3003:36): [True: 33.9k, False: 3.40k]
3004
33.9k
        type->tp_getset = subtype_getsets_full;
3005
33.9k
    }
3006
52.7k
    else if (type->tp_weaklistoffset && !type->tp_dictoffset) {
  Branch (3006:14): [True: 3.40k, False: 49.3k]
  Branch (3006:41): [True: 3.40k, False: 0]
3007
3.40k
        type->tp_getset = subtype_getsets_weakref_only;
3008
3.40k
    }
3009
49.3k
    else if (!type->tp_weaklistoffset && type->tp_dictoffset) {
  Branch (3009:14): [True: 49.3k, False: 0]
  Branch (3009:42): [True: 970, False: 48.3k]
3010
970
        type->tp_getset = subtype_getsets_dict_only;
3011
970
    }
3012
48.3k
    else {
3013
48.3k
        type->tp_getset = NULL;
3014
48.3k
    }
3015
3016
    /* Special case some slots */
3017
86.7k
    if (type->tp_dictoffset != 0 || ctx->nslot > 0) {
  Branch (3017:9): [True: 34.9k, False: 51.7k]
  Branch (3017:37): [True: 1.08k, False: 50.7k]
3018
36.0k
        PyTypeObject *base = ctx->base;
3019
36.0k
        if (base->tp_getattr == NULL && base->tp_getattro == NULL) {
  Branch (3019:13): [True: 36.0k, False: 0]
  Branch (3019:41): [True: 0, False: 36.0k]
3020
0
            type->tp_getattro = PyObject_GenericGetAttr;
3021
0
        }
3022
36.0k
        if (base->tp_setattr == NULL && base->tp_setattro == NULL) {
  Branch (3022:13): [True: 36.0k, False: 0]
  Branch (3022:41): [True: 0, False: 36.0k]
3023
0
            type->tp_setattro = PyObject_GenericSetAttr;
3024
0
        }
3025
36.0k
    }
3026
86.7k
}
3027
3028
3029
/* store type in class' cell if one is supplied */
3030
static int
3031
type_new_set_classcell(PyTypeObject *type)
3032
86.7k
{
3033
86.7k
    PyObject *cell = PyDict_GetItemWithError(
3034
86.7k
            type->tp_dict, &_Py_ID(__classcell__));
Line
Count
Source
374
86.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
86.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
86.7k
    _PyRuntime.global_objects.NAME
3035
86.7k
    if (cell == NULL) {
  Branch (3035:9): [True: 83.5k, False: 3.16k]
3036
83.5k
        if (PyErr_Occurred()) {
  Branch (3036:13): [True: 0, False: 83.5k]
3037
0
            return -1;
3038
0
        }
3039
83.5k
        return 0;
3040
83.5k
    }
3041
3042
    /* At least one method requires a reference to its defining class */
3043
3.16k
    if (!PyCell_Check(cell)) {
Line
Count
Source
18
3.16k
#define PyCell_Check(op) Py_IS_TYPE((op), &PyCell_Type)
Line
Count
Source
155
3.16k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
3.16k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.16k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (3043:9): [True: 5, False: 3.16k]
3044
5
        PyErr_Format(PyExc_TypeError,
3045
5
                     "__classcell__ must be a nonlocal cell, not %.200R",
3046
5
                     Py_TYPE(cell));
Line
Count
Source
138
5
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
3047
5
        return -1;
3048
5
    }
3049
3050
3.16k
    (void)PyCell_Set(cell, (PyObject *) type);
3051
3.16k
    if (PyDict_DelItem(type->tp_dict, &_Py_ID(__classcell__)) < 0) {
Line
Count
Source
374
3.16k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
3.16k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
3.16k
    _PyRuntime.global_objects.NAME
  Branch (3051:9): [True: 0, False: 3.16k]
3052
0
        return -1;
3053
0
    }
3054
3.16k
    return 0;
3055
3.16k
}
3056
3057
3058
static int
3059
type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type)
3060
86.7k
{
3061
86.7k
    if (type_new_set_name(ctx, type) < 0) {
  Branch (3061:9): [True: 2, False: 86.7k]
3062
2
        return -1;
3063
2
    }
3064
3065
86.7k
    if (type_new_set_module(type) < 0) {
  Branch (3065:9): [True: 0, False: 86.7k]
3066
0
        return -1;
3067
0
    }
3068
3069
86.7k
    if (type_new_set_ht_name(type) < 0) {
  Branch (3069:9): [True: 3, False: 86.7k]
3070
3
        return -1;
3071
3
    }
3072
3073
86.7k
    if (type_new_set_doc(type) < 0) {
  Branch (3073:9): [True: 1, False: 86.7k]
3074
1
        return -1;
3075
1
    }
3076
3077
    /* Special-case __new__: if it's a plain function,
3078
       make it a static function */
3079
86.7k
    if (type_new_staticmethod(type, &_Py_ID(__new__)) < 0) {
Line
Count
Source
374
86.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
86.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
86.7k
    _PyRuntime.global_objects.NAME
  Branch (3079:9): [True: 0, False: 86.7k]
3080
0
        return -1;
3081
0
    }
3082
3083
    /* Special-case __init_subclass__ and __class_getitem__:
3084
       if they are plain functions, make them classmethods */
3085
86.7k
    if (type_new_classmethod(type, &_Py_ID(__init_subclass__)) < 0) {
Line
Count
Source
374
86.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
86.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
86.7k
    _PyRuntime.global_objects.NAME
  Branch (3085:9): [True: 0, False: 86.7k]
3086
0
        return -1;
3087
0
    }
3088
86.7k
    if (type_new_classmethod(type, &_Py_ID(__class_getitem__)) < 0) {
Line
Count
Source
374
86.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
86.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
86.7k
    _PyRuntime.global_objects.NAME
  Branch (3088:9): [True: 0, False: 86.7k]
3089
0
        return -1;
3090
0
    }
3091
3092
86.7k
    if (type_new_descriptors(ctx, type) < 0) {
  Branch (3092:9): [True: 0, False: 86.7k]
3093
0
        return -1;
3094
0
    }
3095
3096
86.7k
    type_new_set_slots(ctx, type);
3097
3098
86.7k
    if (type_new_set_classcell(type) < 0) {
  Branch (3098:9): [True: 5, False: 86.7k]
3099
5
        return -1;
3100
5
    }
3101
86.7k
    return 0;
3102
86.7k
}
3103
3104
3105
static int
3106
type_new_get_slots(type_new_ctx *ctx, PyObject *dict)
3107
86.7k
{
3108
86.7k
    PyObject *slots = PyDict_GetItemWithError(dict, &_Py_ID(__slots__));
Line
Count
Source
374
86.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
86.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
86.7k
    _PyRuntime.global_objects.NAME
3109
86.7k
    if (slots == NULL) {
  Branch (3109:9): [True: 77.7k, False: 9.05k]
3110
77.7k
        if (PyErr_Occurred()) {
  Branch (3110:13): [True: 0, False: 77.7k]
3111
0
            return -1;
3112
0
        }
3113
77.7k
        ctx->slots = NULL;
3114
77.7k
        ctx->nslot = 0;
3115
77.7k
        return 0;
3116
77.7k
    }
3117
3118
    // Make it into a tuple
3119
9.05k
    PyObject *new_slots;
3120
9.05k
    if (PyUnicode_Check(slots)) {
Line
Count
Source
115
9.05k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
9.05k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 110, False: 8.94k]
3121
110
        new_slots = PyTuple_Pack(1, slots);
3122
110
    }
3123
8.94k
    else {
3124
8.94k
        new_slots = PySequence_Tuple(slots);
3125
8.94k
    }
3126
9.05k
    if (new_slots == NULL) {
  Branch (3126:9): [True: 1, False: 9.05k]
3127
1
        return -1;
3128
1
    }
3129
9.05k
    assert(PyTuple_CheckExact(new_slots));
3130
9.05k
    ctx->slots = new_slots;
3131
9.05k
    ctx->nslot = PyTuple_GET_SIZE(new_slots);
Line
Count
Source
26
9.05k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
9.05k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.05k
#  define _Py_CAST(type, expr) ((type)(expr))
3132
9.05k
    return 0;
3133
9.05k
}
3134
3135
3136
static PyTypeObject*
3137
type_new_init(type_new_ctx *ctx)
3138
86.7k
{
3139
86.7k
    PyObject *dict = PyDict_Copy(ctx->orig_dict);
3140
86.7k
    if (dict == NULL) {
  Branch (3140:9): [True: 0, False: 86.7k]
3141
0
        goto error;
3142
0
    }
3143
3144
86.7k
    if (type_new_get_slots(ctx, dict) < 0) {
  Branch (3144:9): [True: 1, False: 86.7k]
3145
1
        goto error;
3146
1
    }
3147
86.7k
    assert(!PyErr_Occurred());
3148
3149
86.7k
    if (type_new_slots(ctx, dict) < 0) {
  Branch (3149:9): [True: 18, False: 86.7k]
3150
18
        goto error;
3151
18
    }
3152
3153
86.7k
    PyTypeObject *type = type_new_alloc(ctx);
3154
86.7k
    if (type == NULL) {
  Branch (3154:9): [True: 0, False: 86.7k]
3155
0
        goto error;
3156
0
    }
3157
3158
86.7k
    type->tp_dict = dict;
3159
3160
86.7k
    PyHeapTypeObject *et = (PyHeapTypeObject*)type;
3161
86.7k
    et->ht_slots = ctx->slots;
3162
86.7k
    ctx->slots = NULL;
3163
3164
86.7k
    return type;
3165
3166
19
error:
3167
19
    Py_CLEAR(ctx->slots);
Line
Count
Source
587
19
    do {                                        \
588
19
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
19
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
19
#  define _Py_CAST(type, expr) ((type)(expr))
589
19
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 18, False: 1]
590
18
            (op) = NULL;                        \
591
18
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
18
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
18
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
18
#  define _Py_CAST(type, expr) ((type)(expr))
592
18
        }                                       \
593
19
    } while (0)
  Branch (593:14): [Folded - Ignored]
3168
19
    Py_XDECREF(dict);
Line
Count
Source
613
19
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
19
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
19
#  define _Py_CAST(type, expr) ((type)(expr))
3169
19
    return NULL;
3170
86.7k
}
3171
3172
3173
static PyObject*
3174
type_new_impl(type_new_ctx *ctx)
3175
86.7k
{
3176
86.7k
    PyTypeObject *type = type_new_init(ctx);
3177
86.7k
    if (type == NULL) {
  Branch (3177:9): [True: 19, False: 86.7k]
3178
19
        return NULL;
3179
19
    }
3180
3181
86.7k
    if (type_new_set_attrs(ctx, type) < 0) {
  Branch (3181:9): [True: 11, False: 86.7k]
3182
11
        goto error;
3183
11
    }
3184
3185
    /* Initialize the rest */
3186
86.7k
    if (PyType_Ready(type) < 0) {
  Branch (3186:9): [True: 16, False: 86.7k]
3187
16
        goto error;
3188
16
    }
3189
3190
    // Put the proper slots in place
3191
86.7k
    fixup_slot_dispatchers(type);
3192
3193
86.7k
    if (type->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
Line
Count
Source
359
86.7k
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
  Branch (3193:9): [True: 68.2k, False: 18.5k]
3194
68.2k
        PyHeapTypeObject *et = (PyHeapTypeObject*)type;
3195
68.2k
        et->ht_cached_keys = _PyDict_NewKeysForClass();
3196
68.2k
    }
3197
3198
86.7k
    if (type_new_set_names(type) < 0) {
  Branch (3198:9): [True: 12, False: 86.7k]
3199
12
        goto error;
3200
12
    }
3201
3202
86.7k
    if (type_new_init_subclass(type, ctx->kwds) < 0) {
  Branch (3202:9): [True: 44, False: 86.6k]
3203
44
        goto error;
3204
44
    }
3205
3206
86.6k
    assert(_PyType_CheckConsistency(type));
3207
3208
86.6k
    return (PyObject *)type;
3209
3210
83
error:
3211
83
    Py_DECREF(type);
Line
Count
Source
548
83
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
83
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
83
#  define _Py_CAST(type, expr) ((type)(expr))
3212
83
    return NULL;
3213
86.7k
}
3214
3215
3216
static int
3217
type_new_get_bases(type_new_ctx *ctx, PyObject **type)
3218
87.0k
{
3219
87.0k
    Py_ssize_t nbases = PyTuple_GET_SIZE(ctx->bases);
Line
Count
Source
26
87.0k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
87.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
87.0k
#  define _Py_CAST(type, expr) ((type)(expr))
3220
87.0k
    if (nbases == 0) {
  Branch (3220:9): [True: 27.8k, False: 59.2k]
3221
        // Adjust for empty tuple bases
3222
27.8k
        ctx->base = &PyBaseObject_Type;
3223
27.8k
        PyObject *new_bases = PyTuple_Pack(1, ctx->base);
3224
27.8k
        if (new_bases == NULL) {
  Branch (3224:13): [True: 0, False: 27.8k]
3225
0
            return -1;
3226
0
        }
3227
27.8k
        ctx->bases = new_bases;
3228
27.8k
        return 0;
3229
27.8k
    }
3230
3231
133k
    for (Py_ssize_t i = 0; i < nbases; i++) {
  Branch (3231:28): [True: 73.9k, False: 59.2k]
3232
73.9k
        PyObject *base = PyTuple_GET_ITEM(ctx->bases, i);
Line
Count
Source
28
73.9k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
73.9k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
73.9k
#  define _Py_CAST(type, expr) ((type)(expr))
3233
73.9k
        if (PyType_Check(base)) {
Line
Count
Source
788
73.9k
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
73.9k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
73.9k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (788:28): [True: 73.9k, False: 2]
3234
73.9k
            continue;
3235
73.9k
        }
3236
2
        PyObject *mro_entries;
3237
2
        if (_PyObject_LookupAttr(base, &_Py_ID(__mro_entries__),
Line
Count
Source
374
2
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
2
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
2
    _PyRuntime.global_objects.NAME
  Branch (3237:13): [True: 0, False: 2]
3238
2
                                 &mro_entries) < 0) {
3239
0
            return -1;
3240
0
        }
3241
2
        if (mro_entries != NULL) {
  Branch (3241:13): [True: 1, False: 1]
3242
1
            PyErr_SetString(PyExc_TypeError,
3243
1
                            "type() doesn't support MRO entry resolution; "
3244
1
                            "use types.new_class()");
3245
1
            Py_DECREF(mro_entries);
Line
Count
Source
548
1
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
3246
1
            return -1;
3247
1
        }
3248
2
    }
3249
3250
    // Search the bases for the proper metatype to deal with this
3251
59.2k
    PyTypeObject *winner;
3252
59.2k
    winner = _PyType_CalculateMetaclass(ctx->metatype, ctx->bases);
3253
59.2k
    if (winner == NULL) {
  Branch (3253:9): [True: 1, False: 59.2k]
3254
1
        return -1;
3255
1
    }
3256
3257
59.2k
    if (winner != ctx->metatype) {
  Branch (3257:9): [True: 265, False: 58.9k]
3258
265
        if (winner->tp_new != type_new) {
  Branch (3258:13): [True: 265, False: 0]
3259
            /* Pass it to the winner */
3260
265
            *type = winner->tp_new(winner, ctx->args, ctx->kwds);
3261
265
            if (*type == NULL) {
  Branch (3261:17): [True: 1, False: 264]
3262
1
                return -1;
3263
1
            }
3264
264
            return 1;
3265
265
        }
3266
3267
0
        ctx->metatype = winner;
3268
0
    }
3269
3270
    /* Calculate best base, and check that all bases are type objects */
3271
58.9k
    PyTypeObject *base = best_base(ctx->bases);
3272
58.9k
    if (base == NULL) {
  Branch (3272:9): [True: 15, False: 58.9k]
3273
15
        return -1;
3274
15
    }
3275
3276
58.9k
    ctx->base = base;
3277
58.9k
    ctx->bases = Py_NewRef(ctx->bases);
Line
Count
Source
639
58.9k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
58.9k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
58.9k
#  define _Py_CAST(type, expr) ((type)(expr))
3278
58.9k
    return 0;
3279
58.9k
}
3280
3281
3282
static PyObject *
3283
type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
3284
87.0k
{
3285
87.0k
    assert(args != NULL && PyTuple_Check(args));
3286
87.0k
    assert(kwds == NULL || PyDict_Check(kwds));
3287
3288
    /* Parse arguments: (name, bases, dict) */
3289
87.0k
    PyObject *name, *bases, *orig_dict;
3290
87.0k
    if (!PyArg_ParseTuple(args, "UO!O!:type.__new__",
  Branch (3290:9): [True: 7, False: 87.0k]
3291
87.0k
                          &name,
3292
87.0k
                          &PyTuple_Type, &bases,
3293
87.0k
                          &PyDict_Type, &orig_dict))
3294
7
    {
3295
7
        return NULL;
3296
7
    }
3297
3298
87.0k
    type_new_ctx ctx = {
3299
87.0k
        .metatype = metatype,
3300
87.0k
        .args = args,
3301
87.0k
        .kwds = kwds,
3302
87.0k
        .orig_dict = orig_dict,
3303
87.0k
        .name = name,
3304
87.0k
        .bases = bases,
3305
87.0k
        .base = NULL,
3306
87.0k
        .slots = NULL,
3307
87.0k
        .nslot = 0,
3308
87.0k
        .add_dict = 0,
3309
87.0k
        .add_weak = 0,
3310
87.0k
        .may_add_dict = 0,
3311
87.0k
        .may_add_weak = 0};
3312
87.0k
    PyObject *type = NULL;
3313
87.0k
    int res = type_new_get_bases(&ctx, &type);
3314
87.0k
    if (res < 0) {
  Branch (3314:9): [True: 18, False: 87.0k]
3315
18
        assert(PyErr_Occurred());
3316
18
        return NULL;
3317
18
    }
3318
87.0k
    if (res == 1) {
  Branch (3318:9): [True: 264, False: 86.7k]
3319
264
        assert(type != NULL);
3320
264
        return type;
3321
264
    }
3322
86.7k
    assert(ctx.base != NULL);
3323
86.7k
    assert(ctx.bases != NULL);
3324
3325
86.7k
    type = type_new_impl(&ctx);
3326
86.7k
    Py_DECREF(ctx.bases);
Line
Count
Source
548
86.7k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
86.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.7k
#  define _Py_CAST(type, expr) ((type)(expr))
3327
86.7k
    return type;
3328
87.0k
}
3329
3330
3331
static PyObject *
3332
type_vectorcall(PyObject *metatype, PyObject *const *args,
3333
                 size_t nargsf, PyObject *kwnames)
3334
335k
{
3335
335k
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
3336
335k
    if (nargs == 1 && metatype == (PyObject *)&PyType_Type){
  Branch (3336:9): [True: 265k, False: 69.6k]
  Branch (3336:23): [True: 265k, False: 0]
3337
265k
        if (!_PyArg_NoKwnames("type", kwnames)) {
Line
Count
Source
33
265k
    ((kwnames) == NULL || _PyArg_NoKwnames((funcname), (kwnames)))
  Branch (33:6): [True: 265k, False: 0]
  Branch (33:27): [True: 0, False: 0]
3338
0
            return NULL;
3339
0
        }
3340
265k
        return Py_NewRef(Py_TYPE(args[0]));
Line
Count
Source
639
265k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
265k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
265k
#  define _Py_CAST(type, expr) ((type)(expr))
3341
265k
    }
3342
    /* In other (much less common) cases, fall back to
3343
       more flexible calling conventions. */
3344
69.6k
    PyThreadState *tstate = _PyThreadState_GET();
3345
69.6k
    return _PyObject_MakeTpCall(tstate, metatype, args, nargs, kwnames);
3346
335k
}
3347
3348
/* An array of type slot offsets corresponding to Py_tp_* constants,
3349
  * for use in e.g. PyType_Spec and PyType_GetSlot.
3350
  * Each entry has two offsets: "slot_offset" and "subslot_offset".
3351
  * If is subslot_offset is -1, slot_offset is an offset within the
3352
  * PyTypeObject struct.
3353
  * Otherwise slot_offset is an offset to a pointer to a sub-slots struct
3354
  * (such as "tp_as_number"), and subslot_offset is the offset within
3355
  * that struct.
3356
  * The actual table is generated by a script.
3357
  */
3358
static const PySlot_Offset pyslot_offsets[] = {
3359
    {0, 0},
3360
#include "typeslots.inc"
3361
};
3362
3363
/* Given a PyType_FromMetaclass `bases` argument (NULL, type, or tuple of
3364
 * types), return a tuple of types.
3365
 */
3366
inline static PyObject *
3367
get_bases_tuple(PyObject *bases_in, PyType_Spec *spec)
3368
5.65k
{
3369
5.65k
    if (!bases_in) {
  Branch (3369:9): [True: 3.01k, False: 2.63k]
3370
        /* Default: look in the spec, fall back to (type,). */
3371
3.01k
        PyTypeObject *base = &PyBaseObject_Type;  // borrowed ref
3372
3.01k
        PyObject *bases = NULL;  // borrowed ref
3373
3.01k
        const PyType_Slot *slot;
3374
22.0k
        for (slot = spec->slots; slot->slot; slot++) {
  Branch (3374:34): [True: 19.0k, False: 3.01k]
3375
19.0k
            switch (slot->slot) {
  Branch (3375:21): [True: 18.9k, False: 20]
3376
20
                case Py_tp_base:
Line
Count
Source
49
20
#define Py_tp_base 48
  Branch (3376:17): [True: 20, False: 18.9k]
3377
20
                    base = slot->pfunc;
3378
20
                    break;
3379
0
                case Py_tp_bases:
Line
Count
Source
50
0
#define Py_tp_bases 49
  Branch (3379:17): [True: 0, False: 19.0k]
3380
0
                    bases = slot->pfunc;
3381
0
                    break;
3382
19.0k
            }
3383
19.0k
        }
3384
3.01k
        if (!bases) {
  Branch (3384:13): [True: 3.01k, False: 0]
3385
3.01k
            return PyTuple_Pack(1, base);
3386
3.01k
        }
3387
0
        if (PyTuple_Check(bases)) {
Line
Count
Source
27
0
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
Line
Count
Source
782
0
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 0, False: 0]
3388
0
            return Py_NewRef(bases);
Line
Count
Source
639
0
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
3389
0
        }
3390
0
        PyErr_SetString(PyExc_SystemError, "Py_tp_bases is not a tuple");
3391
0
        return NULL;
3392
0
    }
3393
2.63k
    if (PyTuple_Check(bases_in)) {
Line
Count
Source
27
2.63k
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
Line
Count
Source
782
2.63k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 4, False: 2.63k]
3394
4
        return Py_NewRef(bases_in);
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
3395
4
    }
3396
    // Not a tuple, should be a single type
3397
2.63k
    return PyTuple_Pack(1, bases_in);
3398
2.63k
}
3399
3400
static inline int
3401
check_basicsize_includes_size_and_offsets(PyTypeObject* type)
3402
5.65k
{
3403
5.65k
    if (type->tp_alloc != PyType_GenericAlloc) {
  Branch (3403:9): [True: 0, False: 5.65k]
3404
        // Custom allocators can ignore tp_basicsize
3405
0
        return 1;
3406
0
    }
3407
5.65k
    Py_ssize_t max = (Py_ssize_t)type->tp_basicsize;
3408
3409
5.65k
    if (type->tp_base && type->tp_base->tp_basicsize > type->tp_basicsize) {
  Branch (3409:9): [True: 5.65k, False: 0]
  Branch (3409:26): [True: 0, False: 5.65k]
3410
0
        PyErr_Format(PyExc_TypeError,
3411
0
                     "tp_basicsize for type '%s' (%d) is too small for base '%s' (%d)",
3412
0
                     type->tp_name, type->tp_basicsize,
3413
0
                     type->tp_base->tp_name, type->tp_base->tp_basicsize);
3414
0
        return 0;
3415
0
    }
3416
5.65k
    if (type->tp_weaklistoffset + (Py_ssize_t)sizeof(PyObject*) > max) {
  Branch (3416:9): [True: 0, False: 5.65k]
3417
0
        PyErr_Format(PyExc_TypeError,
3418
0
                     "weaklist offset %d is out of bounds for type '%s' (tp_basicsize = %d)",
3419
0
                     type->tp_weaklistoffset,
3420
0
                     type->tp_name, type->tp_basicsize);
3421
0
        return 0;
3422
0
    }
3423
5.65k
    if (type->tp_dictoffset + (Py_ssize_t)sizeof(PyObject*) > max) {
  Branch (3423:9): [True: 0, False: 5.65k]
3424
0
        PyErr_Format(PyExc_TypeError,
3425
0
                     "dict offset %d is out of bounds for type '%s' (tp_basicsize = %d)",
3426
0
                     type->tp_dictoffset,
3427
0
                     type->tp_name, type->tp_basicsize);
3428
0
        return 0;
3429
0
    }
3430
5.65k
    if (type->tp_vectorcall_offset + (Py_ssize_t)sizeof(vectorcallfunc*) > max) {
  Branch (3430:9): [True: 0, False: 5.65k]
3431
0
        PyErr_Format(PyExc_TypeError,
3432
0
                     "vectorcall offset %d is out of bounds for type '%s' (tp_basicsize = %d)",
3433
0
                     type->tp_vectorcall_offset,
3434
0
                     type->tp_name, type->tp_basicsize);
3435
0
        return 0;
3436
0
    }
3437
5.65k
    return 1;
3438
5.65k
}
3439
3440
PyObject *
3441
PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module,
3442
                     PyType_Spec *spec, PyObject *bases_in)
3443
5.65k
{
3444
    /* Invariant: A non-NULL value in one of these means this function holds
3445
     * a strong reference or owns allocated memory.
3446
     * These get decrefed/freed/returned at the end, on both success and error.
3447
     */
3448
5.65k
    PyHeapTypeObject *res = NULL;
3449
5.65k
    PyTypeObject *type;
3450
5.65k
    PyObject *bases = NULL;
3451
5.65k
    char *tp_doc = NULL;
3452
5.65k
    PyObject *ht_name = NULL;
3453
5.65k
    char *_ht_tpname = NULL;
3454
3455
5.65k
    int r;
3456
3457
    /* Prepare slots that need special handling.
3458
     * Keep in mind that a slot can be given multiple times:
3459
     * if that would cause trouble (leaks, UB, ...), raise an exception.
3460
     */
3461
3462
5.65k
    const PyType_Slot *slot;
3463
5.65k
    Py_ssize_t nmembers = 0;
3464
5.65k
    Py_ssize_t weaklistoffset, dictoffset, vectorcalloffset;
3465
5.65k
    char *res_start;
3466
3467
5.65k
    nmembers = weaklistoffset = dictoffset = vectorcalloffset = 0;
3468
43.0k
    for (slot = spec->slots; slot->slot; slot++) {
  Branch (3468:30): [True: 37.3k, False: 5.65k]
3469
37.3k
        if (slot->slot < 0
  Branch (3469:13): [True: 0, False: 37.3k]
3470
37.3k
            || (size_t)slot->slot >= Py_ARRAY_LENGTH(pyslot_offsets)) {
Line
Count
Source
84
37.3k
    (sizeof(array) / sizeof((array)[0]))
  Branch (3470:16): [True: 0, False: 37.3k]
3471
0
            PyErr_SetString(PyExc_RuntimeError, "invalid slot offset");
3472
0
            goto finally;
3473
0
        }
3474
37.3k
        switch (slot->slot) {
  Branch (3474:17): [True: 28.1k, False: 9.26k]
3475
4.79k
        case Py_tp_members:
Line
Count
Source
73
4.79k
#define Py_tp_members 72
  Branch (3475:9): [True: 4.79k, False: 32.6k]
3476
4.79k
            if (nmembers != 0) {
  Branch (3476:17): [True: 1, False: 4.79k]
3477
1
                PyErr_SetString(
3478
1
                    PyExc_SystemError,
3479
1
                    "Multiple Py_tp_members slots are not supported.");
3480
1
                goto finally;
3481
1
            }
3482
26.1k
            for (const PyMemberDef *memb = slot->pfunc; memb->name != NULL; memb++) {
  Branch (3482:57): [True: 21.3k, False: 4.79k]
3483
21.3k
                nmembers++;
3484
21.3k
                if (strcmp(memb->name, "__weaklistoffset__") == 0) {
  Branch (3484:21): [True: 1.36k, False: 20.0k]
3485
                    // The PyMemberDef must be a Py_ssize_t and readonly
3486
1.36k
                    assert(memb->type == T_PYSSIZET);
3487
1.36k
                    assert(memb->flags == READONLY);
3488
1.36k
                    weaklistoffset = memb->offset;
3489
1.36k
                }
3490
21.3k
                if (strcmp(memb->name, "__dictoffset__") == 0) {
  Branch (3490:21): [True: 197, False: 21.1k]
3491
                    // The PyMemberDef must be a Py_ssize_t and readonly
3492
197
                    assert(memb->type == T_PYSSIZET);
3493
197
                    assert(memb->flags == READONLY);
3494
197
                    dictoffset = memb->offset;
3495
197
                }
3496
21.3k
                if (strcmp(memb->name, "__vectorcalloffset__") == 0) {
  Branch (3496:21): [True: 268, False: 21.1k]
3497
                    // The PyMemberDef must be a Py_ssize_t and readonly
3498
268
                    assert(memb->type == T_PYSSIZET);
3499
268
                    assert(memb->flags == READONLY);
3500
268
                    vectorcalloffset = memb->offset;
3501
268
                }
3502
21.3k
            }
3503
4.79k
            break;
3504
4.47k
        case Py_tp_doc:
Line
Count
Source
57
4.47k
#define Py_tp_doc 56
  Branch (3504:9): [True: 4.47k, False: 32.9k]
3505
            /* For the docstring slot, which usually points to a static string
3506
               literal, we need to make a copy */
3507
4.47k
            if (tp_doc != NULL) {
  Branch (3507:17): [True: 1, False: 4.47k]
3508
1
                PyErr_SetString(
3509
1
                    PyExc_SystemError,
3510
1
                    "Multiple Py_tp_doc slots are not supported.");
3511
1
                goto finally;
3512
1
            }
3513
4.47k
            if (slot->pfunc == NULL) {
  Branch (3513:17): [True: 4, False: 4.46k]
3514
4
                PyObject_Free(tp_doc);
3515
4
                tp_doc = NULL;
3516
4
            }
3517
4.46k
            else {
3518
4.46k
                size_t len = strlen(slot->pfunc)+1;
3519
4.46k
                tp_doc = PyObject_Malloc(len);
3520
4.46k
                if (tp_doc == NULL) {
  Branch (3520:21): [True: 0, False: 4.46k]
3521
0
                    PyErr_NoMemory();
3522
0
                    goto finally;
3523
0
                }
3524
4.46k
                memcpy(tp_doc, slot->pfunc, len);
3525
4.46k
            }
3526
4.47k
            break;
3527
37.3k
        }
3528
37.3k
    }
3529
3530
    /* Prepare the type name and qualname */
3531
3532
5.65k
    if (spec->name == NULL) {
  Branch (3532:9): [True: 0, False: 5.65k]
3533
0
        PyErr_SetString(PyExc_SystemError,
3534
0
                        "Type spec does not define the name field.");
3535
0
        goto finally;
3536
0
    }
3537
3538
5.65k
    const char *s = strrchr(spec->name, '.');
3539
5.65k
    if (s == NULL) {
  Branch (3539:9): [True: 0, False: 5.65k]
3540
0
        s = spec->name;
3541
0
    }
3542
5.65k
    else {
3543
5.65k
        s++;
3544
5.65k
    }
3545
3546
5.65k
    ht_name = PyUnicode_FromString(s);
3547
5.65k
    if (!ht_name) {
  Branch (3547:9): [True: 0, False: 5.65k]
3548
0
        goto finally;
3549
0
    }
3550
3551
    /* Copy spec->name to a buffer we own.
3552
    *
3553
    * Unfortunately, we can't use tp_name directly (with some
3554
    * flag saying that it should be deallocated with the type),
3555
    * because tp_name is public API and may be set independently
3556
    * of any such flag.
3557
    * So, we use a separate buffer, _ht_tpname, that's always
3558
    * deallocated with the type (if it's non-NULL).
3559
    */
3560
5.65k
    Py_ssize_t name_buf_len = strlen(spec->name) + 1;
3561
5.65k
    _ht_tpname = PyMem_Malloc(name_buf_len);
3562
5.65k
    if (_ht_tpname == NULL) {
  Branch (3562:9): [True: 0, False: 5.65k]
3563
0
        goto finally;
3564
0
    }
3565
5.65k
    memcpy(_ht_tpname, spec->name, name_buf_len);
3566
3567
    /* Get a tuple of bases.
3568
     * bases is a strong reference (unlike bases_in).
3569
     */
3570
5.65k
    bases = get_bases_tuple(bases_in, spec);
3571
5.65k
    if (!bases) {
  Branch (3571:9): [True: 0, False: 5.65k]
3572
0
        goto finally;
3573
0
    }
3574
3575
    /* Calculate the metaclass */
3576
3577
5.65k
    if (!metaclass) {
  Branch (3577:9): [True: 5.64k, False: 4]
3578
5.64k
        metaclass = &PyType_Type;
3579
5.64k
    }
3580
5.65k
    metaclass = _PyType_CalculateMetaclass(metaclass, bases);
3581
5.65k
    if (metaclass == NULL) {
  Branch (3581:9): [True: 1, False: 5.65k]
3582
1
        goto finally;
3583
1
    }
3584
5.65k
    if (!PyType_Check(metaclass)) {
Line
Count
Source
788
5.65k
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
5.65k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.65k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (3584:9): [True: 0, False: 5.65k]
3585
0
        PyErr_Format(PyExc_TypeError,
3586
0
                     "Metaclass '%R' is not a subclass of 'type'.",
3587
0
                     metaclass);
3588
0
        goto finally;
3589
0
    }
3590
5.65k
    if (metaclass->tp_new != PyType_Type.tp_new) {
  Branch (3590:9): [True: 1, False: 5.65k]
3591
1
        PyErr_SetString(PyExc_TypeError,
3592
1
                        "Metaclasses with custom tp_new are not supported.");
3593
1
        goto finally;
3594
1
    }
3595
3596
    /* Calculate best base, and check that all bases are type objects */
3597
5.65k
    PyTypeObject *base = best_base(bases);  // borrowed ref
3598
5.65k
    if (base == NULL) {
  Branch (3598:9): [True: 0, False: 5.65k]
3599
0
        goto finally;
3600
0
    }
3601
    // best_base should check Py_TPFLAGS_BASETYPE & raise a proper exception,
3602
    // here we just check its work
3603
5.65k
    assert(_PyType_HasFeature(base, Py_TPFLAGS_BASETYPE));
3604
3605
    /* Allocate the new type
3606
     *
3607
     * Between here and PyType_Ready, we should limit:
3608
     * - calls to Python code
3609
     * - raising exceptions
3610
     * - memory allocations
3611
     */
3612
3613
5.65k
    res = (PyHeapTypeObject*)metaclass->tp_alloc(metaclass, nmembers);
3614
5.65k
    if (res == NULL) {
  Branch (3614:9): [True: 0, False: 5.65k]
3615
0
        goto finally;
3616
0
    }
3617
5.65k
    res_start = (char*)res;
3618
3619
5.65k
    type = &res->ht_type;
3620
    /* The flags must be initialized early, before the GC traverses us */
3621
5.65k
    type->tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE;
Line
Count
Source
375
5.65k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
3622
3623
5.65k
    res->ht_module = Py_XNewRef(module);
Line
Count
Source
640
5.65k
#  define Py_XNewRef(obj) _Py_XNewRef(_PyObject_CAST(obj))
Line
Count
Source
109
5.65k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.65k
#  define _Py_CAST(type, expr) ((type)(expr))
3624
3625
    /* Initialize essential fields */
3626
3627
5.65k
    type->tp_as_async = &res->as_async;
3628
5.65k
    type->tp_as_number = &res->as_number;
3629
5.65k
    type->tp_as_sequence = &res->as_sequence;
3630
5.65k
    type->tp_as_mapping = &res->as_mapping;
3631
5.65k
    type->tp_as_buffer = &res->as_buffer;
3632
3633
    /* Set slots we have prepared */
3634
3635
5.65k
    type->tp_base = (PyTypeObject *)Py_NewRef(base);
Line
Count
Source
639
5.65k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
5.65k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.65k
#  define _Py_CAST(type, expr) ((type)(expr))
3636
5.65k
    type->tp_bases = bases;
3637
5.65k
    bases = NULL;  // We give our reference to bases to the type
3638
3639
5.65k
    type->tp_doc = tp_doc;
3640
5.65k
    tp_doc = NULL;  // Give ownership of the allocated memory to the type
3641
3642
5.65k
    res->ht_qualname = Py_NewRef(ht_name);
Line
Count
Source
639
5.65k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
5.65k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.65k
#  define _Py_CAST(type, expr) ((type)(expr))
3643
5.65k
    res->ht_name = ht_name;
3644
5.65k
    ht_name = NULL;  // Give our reference to to the type
3645
3646
5.65k
    type->tp_name = _ht_tpname;
3647
5.65k
    res->_ht_tpname = _ht_tpname;
3648
5.65k
    _ht_tpname = NULL;  // Give ownership to to the type
3649
3650
    /* Copy the sizes */
3651
3652
5.65k
    type->tp_basicsize = spec->basicsize;
3653
5.65k
    type->tp_itemsize = spec->itemsize;
3654
3655
    /* Copy all the ordinary slots */
3656
3657
43.0k
    for (slot = spec->slots; slot->slot; slot++) {
  Branch (3657:30): [True: 37.3k, False: 5.65k]
3658
37.3k
        switch (slot->slot) {
3659
20
        case Py_tp_base:
Line
Count
Source
49
20
#define Py_tp_base 48
  Branch (3659:9): [True: 20, False: 37.3k]
3660
20
        case Py_tp_bases:
Line
Count
Source
50
20
#define Py_tp_bases 49
  Branch (3660:9): [True: 0, False: 37.3k]
3661
4.49k
        case Py_tp_doc:
Line
Count
Source
57
4.49k
#define Py_tp_doc 56
  Branch (3661:9): [True: 4.47k, False: 32.9k]
3662
            /* Processed above */
3663
4.49k
            break;
3664
4.78k
        case Py_tp_members:
Line
Count
Source
73
4.78k
#define Py_tp_members 72
  Branch (3664:9): [True: 4.78k, False: 32.6k]
3665
4.78k
            {
3666
                /* Move the slots to the heap type itself */
3667
4.78k
                size_t len = Py_TYPE(type)->tp_itemsize * nmembers;
Line
Count
Source
138
4.78k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
4.78k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4.78k
#  define _Py_CAST(type, expr) ((type)(expr))
3668
4.78k
                memcpy(_PyHeapType_GET_MEMBERS(res), slot->pfunc, len);
Line
Count
Source
279
4.78k
    ((PyMemberDef *)(((char *)(etype)) + Py_TYPE(etype)->tp_basicsize))
Line
Count
Source
138
4.78k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
4.78k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4.78k
#  define _Py_CAST(type, expr) ((type)(expr))
3669
4.78k
                type->tp_members = _PyHeapType_GET_MEMBERS(res);
Line
Count
Source
279
4.78k
    ((PyMemberDef *)(((char *)(etype)) + Py_TYPE(etype)->tp_basicsize))
Line
Count
Source
138
4.78k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
4.78k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4.78k
#  define _Py_CAST(type, expr) ((type)(expr))
3670
4.78k
            }
3671
4.78k
            break;
3672
28.1k
        default:
  Branch (3672:9): [True: 28.1k, False: 9.27k]
3673
28.1k
            {
3674
                /* Copy other slots directly */
3675
28.1k
                PySlot_Offset slotoffsets = pyslot_offsets[slot->slot];
3676
28.1k
                short slot_offset = slotoffsets.slot_offset;
3677
28.1k
                if (slotoffsets.subslot_offset == -1) {
  Branch (3677:21): [True: 28.0k, False: 98]
3678
28.0k
                    *(void**)((char*)res_start + slot_offset) = slot->pfunc;
3679
28.0k
                }
3680
98
                else {
3681
98
                    void *procs = *(void**)((char*)res_start + slot_offset);
3682
98
                    short subslot_offset = slotoffsets.subslot_offset;
3683
98
                    *(void**)((char*)procs + subslot_offset) = slot->pfunc;
3684
98
                }
3685
28.1k
            }
3686
28.1k
            break;
3687
37.3k
        }
3688
37.3k
    }
3689
5.65k
    if (type->tp_dealloc == NULL) {
  Branch (3689:9): [True: 67, False: 5.58k]
3690
        /* It's a heap type, so needs the heap types' dealloc.
3691
           subtype_dealloc will call the base type's tp_dealloc, if
3692
           necessary. */
3693
67
        type->tp_dealloc = subtype_dealloc;
3694
67
    }
3695
3696
    /* Set up offsets */
3697
3698
5.65k
    type->tp_vectorcall_offset = vectorcalloffset;
3699
5.65k
    type->tp_weaklistoffset = weaklistoffset;
3700
5.65k
    type->tp_dictoffset = dictoffset;
3701
3702
    /* Ready the type (which includes inheritance).
3703
     *
3704
     * After this call we should generally only touch up what's
3705
     * accessible to Python code, like __dict__.
3706
     */
3707
3708
5.65k
    if (PyType_Ready(type) < 0) {
  Branch (3708:9): [True: 0, False: 5.65k]
3709
0
        goto finally;
3710
0
    }
3711
3712
5.65k
    if (!check_basicsize_includes_size_and_offsets(type)) {
  Branch (3712:9): [True: 0, False: 5.65k]
3713
0
        goto finally;
3714
0
    }
3715
3716
5.65k
    if (type->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
Line
Count
Source
359
5.65k
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
  Branch (3716:9): [True: 1, False: 5.65k]
3717
1
        res->ht_cached_keys = _PyDict_NewKeysForClass();
3718
1
    }
3719
3720
5.65k
    if (type->tp_doc) {
  Branch (3720:9): [True: 4.46k, False: 1.18k]
3721
4.46k
        PyObject *__doc__ = PyUnicode_FromString(_PyType_DocWithoutSignature(type->tp_name, type->tp_doc));
3722
4.46k
        if (!__doc__) {
  Branch (3722:13): [True: 0, False: 4.46k]
3723
0
            goto finally;
3724
0
        }
3725
4.46k
        r = PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), __doc__);
Line
Count
Source
374
4.46k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
4.46k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
4.46k
    _PyRuntime.global_objects.NAME
3726
4.46k
        Py_DECREF(__doc__);
Line
Count
Source
548
4.46k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4.46k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4.46k
#  define _Py_CAST(type, expr) ((type)(expr))
3727
4.46k
        if (r < 0) {
  Branch (3727:13): [True: 0, False: 4.46k]
3728
0
            goto finally;
3729
0
        }
3730
4.46k
    }
3731
3732
5.65k
    if (weaklistoffset) {
  Branch (3732:9): [True: 1.36k, False: 4.28k]
3733
1.36k
        if (PyDict_DelItem((PyObject *)type->tp_dict, &_Py_ID(__weaklistoffset__)) < 0) {
Line
Count
Source
374
1.36k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1.36k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1.36k
    _PyRuntime.global_objects.NAME
  Branch (3733:13): [True: 0, False: 1.36k]
3734
0
            goto finally;
3735
0
        }
3736
1.36k
    }
3737
5.65k
    if (dictoffset) {
  Branch (3737:9): [True: 197, False: 5.45k]
3738
197
        if (PyDict_DelItem((PyObject *)type->tp_dict, &_Py_ID(__dictoffset__)) < 0) {
Line
Count
Source
374
197
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
197
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
197
    _PyRuntime.global_objects.NAME
  Branch (3738:13): [True: 0, False: 197]
3739
0
            goto finally;
3740
0
        }
3741
197
    }
3742
3743
    /* Set type.__module__ */
3744
5.65k
    r = PyDict_Contains(type->tp_dict, &_Py_ID(__module__));
Line
Count
Source
374
5.65k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
5.65k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
5.65k
    _PyRuntime.global_objects.NAME
3745
5.65k
    if (r < 0) {
  Branch (3745:9): [True: 0, False: 5.65k]
3746
0
        goto finally;
3747
0
    }
3748
5.65k
    if (r == 0) {
  Branch (3748:9): [True: 5.65k, False: 0]
3749
5.65k
        s = strrchr(spec->name, '.');
3750
5.65k
        if (s != NULL) {
  Branch (3750:13): [True: 5.65k, False: 0]
3751
5.65k
            PyObject *modname = PyUnicode_FromStringAndSize(
3752
5.65k
                    spec->name, (Py_ssize_t)(s - spec->name));
3753
5.65k
            if (modname == NULL) {
  Branch (3753:17): [True: 0, False: 5.65k]
3754
0
                goto finally;
3755
0
            }
3756
5.65k
            r = PyDict_SetItem(type->tp_dict, &_Py_ID(__module__), modname);
Line
Count
Source
374
5.65k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
5.65k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
5.65k
    _PyRuntime.global_objects.NAME
3757
5.65k
            Py_DECREF(modname);
Line
Count
Source
548
5.65k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
5.65k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.65k
#  define _Py_CAST(type, expr) ((type)(expr))
3758
5.65k
            if (r != 0) {
  Branch (3758:17): [True: 0, False: 5.65k]
3759
0
                goto finally;
3760
0
            }
3761
5.65k
        }
3762
0
        else {
3763
0
            if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
  Branch (3763:17): [True: 0, False: 0]
3764
0
                    "builtin type %.200s has no __module__ attribute",
3765
0
                    spec->name))
3766
0
                goto finally;
3767
0
        }
3768
5.65k
    }
3769
3770
5.65k
    assert(_PyType_CheckConsistency(type));
3771
3772
5.65k
 finally:
3773
5.65k
    if (PyErr_Occurred()) {
  Branch (3773:9): [True: 4, False: 5.65k]
3774
4
        Py_CLEAR(res);
Line
Count
Source
587
4
    do {                                        \
588
4
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
589
4
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 0, False: 4]
590
0
            (op) = NULL;                        \
591
0
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
592
0
        }                                       \
593
4
    } while (0)
  Branch (593:14): [Folded - Ignored]
3775
4
    }
3776
5.65k
    Py_XDECREF(bases);
Line
Count
Source
613
5.65k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
5.65k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.65k
#  define _Py_CAST(type, expr) ((type)(expr))
3777
5.65k
    PyObject_Free(tp_doc);
3778
5.65k
    Py_XDECREF(ht_name);
Line
Count
Source
613
5.65k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
5.65k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.65k
#  define _Py_CAST(type, expr) ((type)(expr))
3779
5.65k
    PyMem_Free(_ht_tpname);
3780
5.65k
    return (PyObject*)res;
3781
5.65k
}
3782
3783
PyObject *
3784
PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
3785
2.02k
{
3786
2.02k
    return PyType_FromMetaclass(NULL, module, spec, bases);
3787
2.02k
}
3788
3789
PyObject *
3790
PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
3791
2.63k
{
3792
2.63k
    return PyType_FromMetaclass(NULL, NULL, spec, bases);
3793
2.63k
}
3794
3795
PyObject *
3796
PyType_FromSpec(PyType_Spec *spec)
3797
996
{
3798
996
    return PyType_FromMetaclass(NULL, NULL, spec, NULL);
3799
996
}
3800
3801
PyObject *
3802
PyType_GetName(PyTypeObject *type)
3803
4
{
3804
4
    return type_name(type, NULL);
3805
4
}
3806
3807
PyObject *
3808
PyType_GetQualName(PyTypeObject *type)
3809
391
{
3810
391
    return type_qualname(type, NULL);
3811
391
}
3812
3813
void *
3814
PyType_GetSlot(PyTypeObject *type, int slot)
3815
1.47M
{
3816
1.47M
    void *parent_slot;
3817
1.47M
    int slots_len = Py_ARRAY_LENGTH(pyslot_offsets);
Line
Count
Source
84
1.47M
    (sizeof(array) / sizeof((array)[0]))
3818
3819
1.47M
    if (slot <= 0 || slot >= slots_len) {
  Branch (3819:9): [True: 1, False: 1.47M]
  Branch (3819:22): [True: 0, False: 1.47M]
3820
1
        PyErr_BadInternalCall();
Line
Count
Source
222
1
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
3821
1
        return NULL;
3822
1
    }
3823
3824
1.47M
    parent_slot = *(void**)((char*)type + pyslot_offsets[slot].slot_offset);
3825
1.47M
    if (parent_slot == NULL) {
  Branch (3825:9): [True: 3, False: 1.47M]
3826
3
        return NULL;
3827
3
    }
3828
    /* Return slot directly if we have no sub slot. */
3829
1.47M
    if (pyslot_offsets[slot].subslot_offset == -1) {
  Branch (3829:9): [True: 1.47M, False: 1]
3830
1.47M
        return parent_slot;
3831
1.47M
    }
3832
1
    return *(void**)((char*)parent_slot + pyslot_offsets[slot].subslot_offset);
3833
1.47M
}
3834
3835
PyObject *
3836
PyType_GetModule(PyTypeObject *type)
3837
5.27M
{
3838
5.27M
    assert(PyType_Check(type));
3839
5.27M
    if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
Line
Count
Source
375
5.27M
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (3839:9): [True: 0, False: 5.27M]
3840
0
        PyErr_Format(
3841
0
            PyExc_TypeError,
3842
0
            "PyType_GetModule: Type '%s' is not a heap type",
3843
0
            type->tp_name);
3844
0
        return NULL;
3845
0
    }
3846
3847
5.27M
    PyHeapTypeObject* et = (PyHeapTypeObject*)type;
3848
5.27M
    if (!et->ht_module) {
  Branch (3848:9): [True: 0, False: 5.27M]
3849
0
        PyErr_Format(
3850
0
            PyExc_TypeError,
3851
0
            "PyType_GetModule: Type '%s' has no associated module",
3852
0
            type->tp_name);
3853
0
        return NULL;
3854
0
    }
3855
5.27M
    return et->ht_module;
3856
3857
5.27M
}
3858
3859
void *
3860
PyType_GetModuleState(PyTypeObject *type)
3861
155k
{
3862
155k
    PyObject *m = PyType_GetModule(type);
3863
155k
    if (m == NULL) {
  Branch (3863:9): [True: 0, False: 155k]
3864
0
        return NULL;
3865
0
    }
3866
155k
    return _PyModule_GetState(m);
3867
155k
}
3868
3869
3870
/* Get the module of the first superclass where the module has the
3871
 * given PyModuleDef.
3872
 */
3873
PyObject *
3874
PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
3875
10.6M
{
3876
10.6M
    assert(PyType_Check(type));
3877
3878
10.6M
    PyObject *mro = type->tp_mro;
3879
    // The type must be ready
3880
10.6M
    assert(mro != NULL);
3881
10.6M
    assert(PyTuple_Check(mro));
3882
    // mro_invoke() ensures that the type MRO cannot be empty, so we don't have
3883
    // to check i < PyTuple_GET_SIZE(mro) at the first loop iteration.
3884
10.6M
    assert(PyTuple_GET_SIZE(mro) >= 1);
3885
3886
10.6M
    Py_ssize_t n = PyTuple_GET_SIZE(mro);
Line
Count
Source
26
10.6M
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
10.6M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10.6M
#  define _Py_CAST(type, expr) ((type)(expr))
3887
10.6M
    for (Py_ssize_t i = 0; i < n; i++) {
  Branch (3887:28): [True: 10.6M, False: 1]
3888
10.6M
        PyObject *super = PyTuple_GET_ITEM(mro, i);
Line
Count
Source
28
10.6M
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
10.6M
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
10.6M
#  define _Py_CAST(type, expr) ((type)(expr))
3889
10.6M
        if(!_PyType_HasFeature((PyTypeObject *)super, Py_TPFLAGS_HEAPTYPE)) {
Line
Count
Source
375
10.6M
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (3889:12): [True: 1, False: 10.6M]
3890
            // Static types in the MRO need to be skipped
3891
1
            continue;
3892
1
        }
3893
3894
10.6M
        PyHeapTypeObject *ht = (PyHeapTypeObject*)super;
3895
10.6M
        PyObject *module = ht->ht_module;
3896
10.6M
        if (module && _PyModule_GetDef(module) == def) {
  Branch (3896:13): [True: 10.6M, False: 36.5k]
  Branch (3896:23): [True: 10.6M, False: 1]
3897
10.6M
            return module;
3898
10.6M
        }
3899
10.6M
    }
3900
3901
1
    PyErr_Format(
3902
1
        PyExc_TypeError,
3903
1
        "PyType_GetModuleByDef: No superclass of '%s' has the given module",
3904
1
        type->tp_name);
3905
1
    return NULL;
3906
10.6M
}
3907
3908
3909
/* Internal API to look for a name through the MRO, bypassing the method cache.
3910
   This returns a borrowed reference, and might set an exception.
3911
   'error' is set to: -1: error with exception; 1: error without exception; 0: ok */
3912
static PyObject *
3913
find_name_in_mro(PyTypeObject *type, PyObject *name, int *error)
3914
14.4M
{
3915
14.4M
    Py_hash_t hash;
3916
14.4M
    if (!PyUnicode_CheckExact(name) ||
Line
Count
Source
116
14.4M
#define PyUnicode_CheckExact(op) Py_IS_TYPE((op), &PyUnicode_Type)
Line
Count
Source
155
28.9M
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
14.4M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14.4M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (3916:9): [True: 6, False: 14.4M]
3917
14.4M
        (hash = _PyASCIIObject_CAST(name)->hash) == -1)
Line
Count
Source
169
14.4M
    (assert(PyUnicode_Check(op)), \
170
14.4M
     _Py_CAST(PyASCIIObject*, (op)))
Line
Count
Source
71
14.4M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (3917:9): [True: 3.09M, False: 11.3M]
3918
3.09M
    {
3919
3.09M
        hash = PyObject_Hash(name);
3920
3.09M
        if (hash == -1) {
  Branch (3920:13): [True: 0, False: 3.09M]
3921
0
            *error = -1;
3922
0
            return NULL;
3923
0
        }
3924
3.09M
    }
3925
3926
    /* Look in tp_dict of types in MRO */
3927
14.4M
    PyObject *mro = type->tp_mro;
3928
14.4M
    if (mro == NULL) {
  Branch (3928:9): [True: 3, False: 14.4M]
3929
3
        if ((type->tp_flags & Py_TPFLAGS_READYING) == 0) {
Line
Count
Source
391
3
#define Py_TPFLAGS_READYING (1UL << 13)
  Branch (3929:13): [True: 1, False: 2]
3930
1
            if (PyType_Ready(type) < 0) {
  Branch (3930:17): [True: 0, False: 1]
3931
0
                *error = -1;
3932
0
                return NULL;
3933
0
            }
3934
1
            mro = type->tp_mro;
3935
1
        }
3936
3
        if (mro == NULL) {
  Branch (3936:13): [True: 2, False: 1]
3937
2
            *error = 1;
3938
2
            return NULL;
3939
2
        }
3940
3
    }
3941
3942
14.4M
    PyObject *res = NULL;
3943
    /* Keep a strong reference to mro because type->tp_mro can be replaced
3944
       during dict lookup, e.g. when comparing to non-string keys. */
3945
14.4M
    Py_INCREF(mro);
Line
Count
Source
512
14.4M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
14.4M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14.4M
#  define _Py_CAST(type, expr) ((type)(expr))
3946
14.4M
    Py_ssize_t n = PyTuple_GET_SIZE(mro);
Line
Count
Source
26
14.4M
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
14.4M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14.4M
#  define _Py_CAST(type, expr) ((type)(expr))
3947
53.2M
    for (Py_ssize_t i = 0; i < n; i++) {
  Branch (3947:28): [True: 44.8M, False: 8.34M]
3948
44.8M
        PyObject *base = PyTuple_GET_ITEM(mro, i);
Line
Count
Source
28
44.8M
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
44.8M
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
44.8M
#  define _Py_CAST(type, expr) ((type)(expr))
3949
44.8M
        PyObject *dict = _PyType_CAST(base)->tp_dict;
Line
Count
Source
792
44.8M
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
44.8M
#  define _Py_CAST(type, expr) ((type)(expr))
3950
44.8M
        assert(dict && PyDict_Check(dict));
3951
44.8M
        res = _PyDict_GetItem_KnownHash(dict, name, hash);
3952
44.8M
        if (res != NULL) {
  Branch (3952:13): [True: 6.13M, False: 38.7M]
3953
6.13M
            break;
3954
6.13M
        }
3955
38.7M
        if (PyErr_Occurred()) {
  Branch (3955:13): [True: 0, False: 38.7M]
3956
0
            *error = -1;
3957
0
            goto done;
3958
0
        }
3959
38.7M
    }
3960
14.4M
    *error = 0;
3961
14.4M
done:
3962
14.4M
    Py_DECREF(mro);
Line
Count
Source
548
14.4M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
14.4M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14.4M
#  define _Py_CAST(type, expr) ((type)(expr))
3963
14.4M
    return res;
3964
14.4M
}
3965
3966
/* Internal API to look for a name through the MRO.
3967
   This returns a borrowed reference, and doesn't set an exception! */
3968
PyObject *
3969
_PyType_Lookup(PyTypeObject *type, PyObject *name)
3970
238M
{
3971
238M
    PyObject *res;
3972
238M
    int error;
3973
3974
238M
    unsigned int h = MCACHE_HASH_METHOD(type, name);
Line
Count
Source
40
238M
    MCACHE_HASH((type)->tp_version_tag, ((Py_ssize_t)(name)) >> 3)
Line
Count
Source
36
238M
        (((unsigned int)(version) ^ (unsigned int)(name_hash))          \
37
238M
         & ((1 << MCACHE_SIZE_EXP) - 1))
Line
Count
Source
30
238M
#define MCACHE_SIZE_EXP 12
3975
238M
    struct type_cache *cache = get_type_cache();
3976
238M
    struct type_cache_entry *entry = &cache->hashtable[h];
3977
238M
    if (entry->version == type->tp_version_tag &&
  Branch (3977:9): [True: 235M, False: 2.64M]
3978
238M
        entry->name == name) {
  Branch (3978:9): [True: 232M, False: 3.14M]
3979
#if MCACHE_STATS
3980
        cache->hits++;
3981
#endif
3982
232M
        assert(_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG));
3983
232M
        return entry->value;
3984
232M
    }
3985
3986
    /* We may end up clearing live exceptions below, so make sure it's ours. */
3987
5.78M
    assert(!PyErr_Occurred());
3988
3989
5.78M
    res = find_name_in_mro(type, name, &error);
3990
    /* Only put NULL results into cache if there was no error. */
3991
5.78M
    if (error) {
  Branch (3991:9): [True: 2, False: 5.78M]
3992
        /* It's not ideal to clear the error condition,
3993
           but this function is documented as not setting
3994
           an exception, and I don't want to change that.
3995
           E.g., when PyType_Ready() can't proceed, it won't
3996
           set the "ready" flag, so future attempts to ready
3997
           the same type will call it again -- hopefully
3998
           in a context that propagates the exception out.
3999
        */
4000
2
        if (error == -1) {
  Branch (4000:13): [True: 0, False: 2]
4001
0
            PyErr_Clear();
4002
0
        }
4003
2
        return NULL;
4004
2
    }
4005
4006
5.78M
    if (MCACHE_CACHEABLE_NAME(name) && assign_version_tag(cache, type)) {
Line
Count
Source
42
5.78M
        PyUnicode_CheckExact(name) &&                           \
Line
Count
Source
116
5.78M
#define PyUnicode_CheckExact(op) Py_IS_TYPE((op), &PyUnicode_Type)
Line
Count
Source
155
11.5M
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
5.78M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.78M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 5.78M, False: 6]
43
5.78M
        PyUnicode_IS_READY(name) &&                             \
Line
Count
Source
197
11.5M
#define PyUnicode_IS_READY(op) PyUnicode_IS_READY(_PyObject_CAST(op))
Line
Count
Source
109
5.78M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.78M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (197:32): [True: 5.78M, False: 0]
44
11.5M
        (PyUnicode_GET_LENGTH(name) <= MCACHE_MAX_ATTR_SIZE)
Line
Count
Source
275
5.78M
#define PyUnicode_GET_LENGTH(op) PyUnicode_GET_LENGTH(_PyObject_CAST(op))
Line
Count
Source
109
5.78M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.78M
#  define _Py_CAST(type, expr) ((type)(expr))
        (PyUnicode_GET_LENGTH(name) <= MCACHE_MAX_ATTR_SIZE)
Line
Count
Source
34
5.78M
#define MCACHE_MAX_ATTR_SIZE    100
  Branch (44:9): [True: 5.78M, False: 9]
  Branch (4006:40): [True: 5.78M, False: 0]
4007
5.78M
        h = MCACHE_HASH_METHOD(type, name);
Line
Count
Source
40
5.78M
    MCACHE_HASH((type)->tp_version_tag, ((Py_ssize_t)(name)) >> 3)
Line
Count
Source
36
5.78M
        (((unsigned int)(version) ^ (unsigned int)(name_hash))          \
37
5.78M
         & ((1 << MCACHE_SIZE_EXP) - 1))
Line
Count
Source
30
5.78M
#define MCACHE_SIZE_EXP 12
4008
5.78M
        struct type_cache_entry *entry = &cache->hashtable[h];
4009
5.78M
        entry->version = type->tp_version_tag;
4010
5.78M
        entry->value = res;  /* borrowed */
4011
5.78M
        assert(_PyASCIIObject_CAST(name)->hash != -1);
4012
#if MCACHE_STATS
4013
        if (entry->name != Py_None && entry->name != name) {
4014
            cache->collisions++;
4015
        }
4016
        else {
4017
            cache->misses++;
4018
        }
4019
#endif
4020
5.78M
        assert(_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG));
4021
5.78M
        Py_SETREF(entry->name, Py_NewRef(name));
Line
Count
Source
332
5.78M
    do {                                        \
333
5.78M
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
5.78M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.78M
#  define _Py_CAST(type, expr) ((type)(expr))
334
5.78M
        (op) = (op2);                           \
335
5.78M
        Py_DECREF(_py_tmp);                     \
Line
Count
Source
548
5.78M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
5.78M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.78M
#  define _Py_CAST(type, expr) ((type)(expr))
336
5.78M
    } while (0)
  Branch (336:14): [Folded - Ignored]
4022
5.78M
    }
4023
5.78M
    return res;
4024
5.78M
}
4025
4026
PyObject *
4027
_PyType_LookupId(PyTypeObject *type, _Py_Identifier *name)
4028
0
{
4029
0
    PyObject *oname;
4030
0
    oname = _PyUnicode_FromId(name);   /* borrowed */
4031
0
    if (oname == NULL)
  Branch (4031:9): [True: 0, False: 0]
4032
0
        return NULL;
4033
0
    return _PyType_Lookup(type, oname);
4034
0
}
4035
4036
/* Check if the "readied" PyUnicode name
4037
   is a double-underscore special name. */
4038
static int
4039
is_dunder_name(PyObject *name)
4040
495k
{
4041
495k
    Py_ssize_t length = PyUnicode_GET_LENGTH(name);
Line
Count
Source
275
495k
#define PyUnicode_GET_LENGTH(op) PyUnicode_GET_LENGTH(_PyObject_CAST(op))
Line
Count
Source
109
495k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
495k
#  define _Py_CAST(type, expr) ((type)(expr))
4042
495k
    int kind = PyUnicode_KIND(name);
Line
Count
Source
236
495k
#define PyUnicode_KIND(op) (_PyASCIIObject_CAST(op)->state.kind)
Line
Count
Source
169
495k
    (assert(PyUnicode_Check(op)), \
170
495k
     _Py_CAST(PyASCIIObject*, (op)))
Line
Count
Source
71
495k
#  define _Py_CAST(type, expr) ((type)(expr))
4043
    /* Special names contain at least "__x__" and are always ASCII. */
4044
495k
    if (length > 4 && kind == PyUnicode_1BYTE_KIND) {
  Branch (4044:9): [True: 488k, False: 7.01k]
  Branch (4044:23): [True: 488k, False: 0]
4045
488k
        const Py_UCS1 *characters = PyUnicode_1BYTE_DATA(name);
Line
Count
Source
267
488k
#define PyUnicode_1BYTE_DATA(op) _Py_STATIC_CAST(Py_UCS1*, PyUnicode_DATA(op))
Line
Count
Source
70
488k
#  define _Py_STATIC_CAST(type, expr) ((type)(expr))
4046
488k
        return (
4047
488k
            ((characters[length-2] == '_') && (characters[length-1] == '_')) &&
  Branch (4047:14): [True: 424k, False: 64.5k]
  Branch (4047:47): [True: 424k, False: 183]
4048
488k
            ((characters[0] == '_') && (characters[1] == '_'))
  Branch (4048:14): [True: 424k, False: 0]
  Branch (4048:40): [True: 424k, False: 0]
4049
488k
        );
4050
488k
    }
4051
7.01k
    return 0;
4052
495k
}
4053
4054
/* This is similar to PyObject_GenericGetAttr(),
4055
   but uses _PyType_Lookup() instead of just looking in type->tp_dict. */
4056
static PyObject *
4057
type_getattro(PyTypeObject *type, PyObject *name)
4058
8.11M
{
4059
8.11M
    PyTypeObject *metatype = Py_TYPE(type);
Line
Count
Source
138
8.11M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
8.11M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8.11M
#  define _Py_CAST(type, expr) ((type)(expr))
4060
8.11M
    PyObject *meta_attribute, *attribute;
4061
8.11M
    descrgetfunc meta_get;
4062
8.11M
    PyObject* res;
4063
4064
8.11M
    if (!PyUnicode_Check(name)) {
Line
Count
Source
115
8.11M
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
8.11M
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (4064:9): [True: 1, False: 8.11M]
4065
1
        PyErr_Format(PyExc_TypeError,
4066
1
                     "attribute name must be string, not '%.200s'",
4067
1
                     Py_TYPE(name)->tp_name);
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
4068
1
        return NULL;
4069
1
    }
4070
4071
    /* Initialize this type (we'll assume the metatype is initialized) */
4072
8.11M
    if (!_PyType_IsReady(type)) {
Line
Count
Source
241
8.11M
#define _PyType_IsReady(type) ((type)->tp_dict != NULL)
  Branch (4072:9): [True: 1, False: 8.11M]
4073
1
        if (PyType_Ready(type) < 0)
  Branch (4073:13): [True: 0, False: 1]
4074
0
            return NULL;
4075
1
    }
4076
4077
    /* No readable descriptor found yet */
4078
8.11M
    meta_get = NULL;
4079
4080
    /* Look for the attribute in the metatype */
4081
8.11M
    meta_attribute = _PyType_Lookup(metatype, name);
4082
4083
8.11M
    if (meta_attribute != NULL) {
  Branch (4083:9): [True: 5.88M, False: 2.23M]
4084
5.88M
        Py_INCREF(meta_attribute);
Line
Count
Source
512
5.88M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
5.88M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.88M
#  define _Py_CAST(type, expr) ((type)(expr))
4085
5.88M
        meta_get = Py_TYPE(meta_attribute)->tp_descr_get;
Line
Count
Source
138
5.88M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
5.88M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.88M
#  define _Py_CAST(type, expr) ((type)(expr))
4086
4087
5.88M
        if (meta_get != NULL && PyDescr_IsData(meta_attribute)) {
  Branch (4087:13): [True: 3.52M, False: 2.36M]
  Branch (4087:33): [True: 2.35M, False: 1.16M]
4088
            /* Data descriptors implement tp_descr_set to intercept
4089
             * writes. Assume the attribute is not overridden in
4090
             * type's tp_dict (and bases): call the descriptor now.
4091
             */
4092
2.35M
            res = meta_get(meta_attribute, (PyObject *)type,
4093
2.35M
                           (PyObject *)metatype);
4094
2.35M
            Py_DECREF(meta_attribute);
Line
Count
Source
548
2.35M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
2.35M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.35M
#  define _Py_CAST(type, expr) ((type)(expr))
4095
2.35M
            return res;
4096
2.35M
        }
4097
5.88M
    }
4098
4099
    /* No data descriptor found on metatype. Look in tp_dict of this
4100
     * type and its bases */
4101
5.76M
    attribute = _PyType_Lookup(type, name);
4102
5.76M
    if (attribute != NULL) {
  Branch (4102:9): [True: 5.60M, False: 162k]
4103
        /* Implement descriptor functionality, if any */
4104
5.60M
        Py_INCREF(attribute);
Line
Count
Source
512
5.60M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
5.60M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.60M
#  define _Py_CAST(type, expr) ((type)(expr))
4105
5.60M
        descrgetfunc local_get = Py_TYPE(attribute)->tp_descr_get;
Line
Count
Source
138
5.60M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
5.60M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.60M
#  define _Py_CAST(type, expr) ((type)(expr))
4106
4107
5.60M
        Py_XDECREF(meta_attribute);
Line
Count
Source
613
5.60M
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
5.60M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5.60M
#  define _Py_CAST(type, expr) ((type)(expr))
4108
4109
5.60M
        if (local_get != NULL) {
  Branch (4109:13): [True: 4.38M, False: 1.21M]
4110
            /* NULL 2nd argument indicates the descriptor was
4111
             * found on the target object itself (or a base)  */
4112
4.38M
            res = local_get(attribute, (PyObject *)NULL,
4113
4.38M
                            (PyObject *)type);
4114
4.38M
            Py_DECREF(attribute);
Line
Count
Source
548
4.38M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4.38M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4.38M
#  define _Py_CAST(type, expr) ((type)(expr))
4115
4.38M
            return res;
4116
4.38M
        }
4117
4118
1.21M
        return attribute;
4119
5.60M
    }
4120
4121
    /* No attribute found in local __dict__ (or bases): use the
4122
     * descriptor from the metatype, if any */
4123
162k
    if (meta_get != NULL) {
  Branch (4123:9): [True: 36.5k, False: 125k]
4124
36.5k
        PyObject *res;
4125
36.5k
        res = meta_get(meta_attribute, (PyObject *)type,
4126
36.5k
                       (PyObject *)metatype);
4127
36.5k
        Py_DECREF(meta_attribute);
Line
Count
Source
548
36.5k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
36.5k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
36.5k
#  define _Py_CAST(type, expr) ((type)(expr))
4128
36.5k
        return res;
4129
36.5k
    }
4130
4131
    /* If an ordinary attribute was found on the metatype, return it now */
4132
125k
    if (meta_attribute != NULL) {
  Branch (4132:9): [True: 6, False: 125k]
4133
6
        return meta_attribute;
4134
6
    }
4135
4136
    /* Give up */
4137
125k
    PyErr_Format(PyExc_AttributeError,
4138
125k
                 "type object '%.50s' has no attribute '%U'",
4139
125k
                 type->tp_name, name);
4140
125k
    return NULL;
4141
125k
}
4142
4143
static int
4144
type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
4145
496k
{
4146
496k
    int res;
4147
496k
    if (type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) {
Line
Count
Source
372
496k
#define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
  Branch (4147:9): [True: 585, False: 495k]
4148
585
        PyErr_Format(
4149
585
            PyExc_TypeError,
4150
585
            "cannot set %R attribute of immutable type '%s'",
4151
585
            name, type->tp_name);
4152
585
        return -1;
4153
585
    }
4154
495k
    if (PyUnicode_Check(name)) {
Line
Count
Source
115
495k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
495k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 495k, False: 1]
4155
495k
        if (PyUnicode_CheckExact(name)) {
Line
Count
Source
116
495k
#define PyUnicode_CheckExact(op) Py_IS_TYPE((op), &PyUnicode_Type)
Line
Count
Source
155
495k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
495k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
495k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 495k, False: 0]
4156
495k
            if (PyUnicode_READY(name) == -1)
Line
Count
Source
390
495k
#define PyUnicode_READY(op) PyUnicode_READY(_PyObject_CAST(op))
Line
Count
Source
109
495k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
495k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (4156:17): [True: 0, False: 495k]
4157
0
                return -1;
4158
495k
            Py_INCREF(name);
Line
Count
Source
512
495k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
495k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
495k
#  define _Py_CAST(type, expr) ((type)(expr))
4159
495k
        }
4160
0
        else {
4161
0
            name = _PyUnicode_Copy(name);
4162
0
            if (name == NULL)
  Branch (4162:17): [True: 0, False: 0]
4163
0
                return -1;
4164
0
        }
4165
        /* bpo-40521: Interned strings are shared by all subinterpreters */
4166
495k
        if (!PyUnicode_CHECK_INTERNED(name)) {
Line
Count
Source
191
495k
#define PyUnicode_CHECK_INTERNED(op) PyUnicode_CHECK_INTERNED(_PyObject_CAST(op))
Line
Count
Source
109
495k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
495k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (4166:13): [True: 2, False: 495k]
4167
2
            PyUnicode_InternInPlace(&name);
4168
2
            if (!PyUnicode_CHECK_INTERNED(name)) {
Line
Count
Source
191
2
#define PyUnicode_CHECK_INTERNED(op) PyUnicode_CHECK_INTERNED(_PyObject_CAST(op))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (4168:17): [True: 0, False: 2]
4169
0
                PyErr_SetString(PyExc_MemoryError,
4170
0
                                "Out of memory interning an attribute name");
4171
0
                Py_DECREF(name);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
4172
0
                return -1;
4173
0
            }
4174
2
        }
4175
495k
    }
4176
1
    else {
4177
        /* Will fail in _PyObject_GenericSetAttrWithDict. */
4178
1
        Py_INCREF(name);
Line
Count
Source
512
1
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
4179
1
    }
4180
495k
    res = _PyObject_GenericSetAttrWithDict((PyObject *)type, name, value, NULL);
4181
495k
    if (res == 0) {
  Branch (4181:9): [True: 495k, False: 50]
4182
        /* Clear the VALID_VERSION flag of 'type' and all its
4183
           subclasses.  This could possibly be unified with the
4184
           update_subclasses() recursion in update_slot(), but carefully:
4185
           they each have their own conditions on which to stop
4186
           recursing into subclasses. */
4187
495k
        PyType_Modified(type);
4188
4189
495k
        if (is_dunder_name(name)) {
  Branch (4189:13): [True: 424k, False: 71.7k]
4190
424k
            res = update_slot(type, name);
4191
424k
        }
4192
495k
        assert(_PyType_CheckConsistency(type));
4193
495k
    }
4194
495k
    Py_DECREF(name);
Line
Count
Source
548
495k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
495k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
495k
#  define _Py_CAST(type, expr) ((type)(expr))
4195
495k
    return res;
4196
495k
}
4197
4198
extern void
4199
_PyDictKeys_DecRef(PyDictKeysObject *keys);
4200
4201
4202
static void
4203
type_dealloc_common(PyTypeObject *type)
4204
111k
{
4205
111k
    if (type->tp_bases != NULL) {
  Branch (4205:9): [True: 111k, False: 0]
4206
111k
        PyObject *tp, *val, *tb;
4207
111k
        PyErr_Fetch(&tp, &val, &tb);
4208
111k
        remove_all_subclasses(type, type->tp_bases);
4209
111k
        PyErr_Restore(tp, val, tb);
4210
111k
    }
4211
111k
}
4212
4213
4214
void
4215
_PyStaticType_Dealloc(PyTypeObject *type)
4216
20.4k
{
4217
    // If a type still has subtypes, it cannot be deallocated.
4218
    // A subtype can inherit attributes and methods of its parent type,
4219
    // and a type must no longer be used once it's deallocated.
4220
20.4k
    if (type->tp_subclasses != NULL) {
  Branch (4220:9): [True: 103, False: 20.3k]
4221
103
        return;
4222
103
    }
4223
4224
20.3k
    type_dealloc_common(type);
4225
4226
20.3k
    Py_CLEAR(type->tp_dict);
Line
Count
Source
587
20.3k
    do {                                        \
588
20.3k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
20.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.3k
#  define _Py_CAST(type, expr) ((type)(expr))
589
20.3k
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 20.3k, False: 0]
590
20.3k
            (op) = NULL;                        \
591
20.3k
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
20.3k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
20.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.3k
#  define _Py_CAST(type, expr) ((type)(expr))
592
20.3k
        }                                       \
593
20.3k
    } while (0)
  Branch (593:14): [Folded - Ignored]
4227
20.3k
    Py_CLEAR(type->tp_bases);
Line
Count
Source
587
20.3k
    do {                                        \
588
20.3k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
20.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.3k
#  define _Py_CAST(type, expr) ((type)(expr))
589
20.3k
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 20.3k, False: 0]
590
20.3k
            (op) = NULL;                        \
591
20.3k
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
20.3k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
20.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.3k
#  define _Py_CAST(type, expr) ((type)(expr))
592
20.3k
        }                                       \
593
20.3k
    } while (0)
  Branch (593:14): [Folded - Ignored]
4228
20.3k
    Py_CLEAR(type->tp_mro);
Line
Count
Source
587
20.3k
    do {                                        \
588
20.3k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
20.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.3k
#  define _Py_CAST(type, expr) ((type)(expr))
589
20.3k
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 20.3k, False: 0]
590
20.3k
            (op) = NULL;                        \
591
20.3k
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
20.3k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
20.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.3k
#  define _Py_CAST(type, expr) ((type)(expr))
592
20.3k
        }                                       \
593
20.3k
    } while (0)
  Branch (593:14): [Folded - Ignored]
4229
20.3k
    Py_CLEAR(type->tp_cache);
Line
Count
Source
587
20.3k
    do {                                        \
588
20.3k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
20.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.3k
#  define _Py_CAST(type, expr) ((type)(expr))
589
20.3k
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 0, False: 20.3k]
590
0
            (op) = NULL;                        \
591
0
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
592
0
        }                                       \
593
20.3k
    } while (0)
  Branch (593:14): [Folded - Ignored]
4230
    // type->tp_subclasses is NULL
4231
4232
    // PyObject_ClearWeakRefs() raises an exception if Py_REFCNT() != 0
4233
20.3k
    if (Py_REFCNT(type) == 0) {
Line
Count
Source
129
20.3k
#  define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob))
Line
Count
Source
109
20.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
20.3k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (4233:9): [True: 0, False: 20.3k]
4234
0
        PyObject_ClearWeakRefs((PyObject *)type);
4235
0
    }
4236
4237
20.3k
    type->tp_flags &= ~Py_TPFLAGS_READY;
Line
Count
Source
388
20.3k
#define Py_TPFLAGS_READY (1UL << 12)
4238
20.3k
}
4239
4240
4241
static void
4242
type_dealloc(PyTypeObject *type)
4243
91.2k
{
4244
    // Assert this is a heap-allocated type object
4245
91.2k
    _PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE);
Line
Count
Source
390
91.2k
    _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
Line
Count
Source
388
91.2k
    _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
Line
Count
Source
377
91.2k
    ((void)0)
4246
4247
91.2k
    _PyObject_GC_UNTRACK(type);
Line
Count
Source
187
91.2k
        _PyObject_GC_UNTRACK(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4248
4249
91.2k
    type_dealloc_common(type);
4250
4251
    // PyObject_ClearWeakRefs() raises an exception if Py_REFCNT() != 0
4252
91.2k
    assert(Py_REFCNT(type) == 0);
4253
91.2k
    PyObject_ClearWeakRefs((PyObject *)type);
4254
4255
91.2k
    Py_XDECREF(type->tp_base);
Line
Count
Source
613
91.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4256
91.2k
    Py_XDECREF(type->tp_dict);
Line
Count
Source
613
91.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4257
91.2k
    Py_XDECREF(type->tp_bases);
Line
Count
Source
613
91.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4258
91.2k
    Py_XDECREF(type->tp_mro);
Line
Count
Source
613
91.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4259
91.2k
    Py_XDECREF(type->tp_cache);
Line
Count
Source
613
91.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4260
91.2k
    Py_XDECREF(type->tp_subclasses);
Line
Count
Source
613
91.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4261
4262
    /* A type's tp_doc is heap allocated, unlike the tp_doc slots
4263
     * of most other objects.  It's okay to cast it to char *.
4264
     */
4265
91.2k
    PyObject_Free((char *)type->tp_doc);
4266
4267
91.2k
    PyHeapTypeObject *et = (PyHeapTypeObject *)type;
4268
91.2k
    Py_XDECREF(et->ht_name);
Line
Count
Source
613
91.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4269
91.2k
    Py_XDECREF(et->ht_qualname);
Line
Count
Source
613
91.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4270
91.2k
    Py_XDECREF(et->ht_slots);
Line
Count
Source
613
91.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4271
91.2k
    if (et->ht_cached_keys) {
  Branch (4271:9): [True: 67.8k, False: 23.4k]
4272
67.8k
        _PyDictKeys_DecRef(et->ht_cached_keys);
4273
67.8k
    }
4274
91.2k
    Py_XDECREF(et->ht_module);
Line
Count
Source
613
91.2k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4275
91.2k
    PyMem_Free(et->_ht_tpname);
4276
91.2k
    Py_TYPE(type)->tp_free((PyObject *)type);
Line
Count
Source
138
91.2k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
4277
91.2k
}
4278
4279
4280
PyObject*
4281
_PyType_GetSubclasses(PyTypeObject *self)
4282
18.7k
{
4283
18.7k
    PyObject *list = PyList_New(0);
4284
18.7k
    if (list == NULL) {
  Branch (4284:9): [True: 0, False: 18.7k]
4285
0
        return NULL;
4286
0
    }
4287
4288
18.7k
    PyObject *subclasses = self->tp_subclasses;  // borrowed ref
4289
18.7k
    if (subclasses == NULL) {
  Branch (4289:9): [True: 14.7k, False: 3.98k]
4290
14.7k
        return list;
4291
14.7k
    }
4292
3.98k
    assert(PyDict_CheckExact(subclasses));
4293
    // The loop cannot modify tp_subclasses, there is no need
4294
    // to hold a strong reference (use a borrowed reference).
4295
4296
3.98k
    Py_ssize_t i = 0;
4297
3.98k
    PyObject *ref;  // borrowed ref
4298
18.9k
    while (PyDict_Next(subclasses, &i, NULL, &ref)) {
  Branch (4298:12): [True: 15.0k, False: 3.98k]
4299
15.0k
        assert(PyWeakref_CheckRef(ref));
4300
15.0k
        PyObject *obj = PyWeakref_GET_OBJECT(ref);  // borrowed ref
Line
Count
Source
56
15.0k
#define PyWeakref_GET_OBJECT(ref) PyWeakref_GET_OBJECT(_PyObject_CAST(ref))
Line
Count
Source
109
15.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
15.0k
#  define _Py_CAST(type, expr) ((type)(expr))
4301
15.0k
        if (obj == Py_None) {
Line
Count
Source
654
15.0k
#define Py_None (&_Py_NoneStruct)
  Branch (4301:13): [True: 0, False: 15.0k]
4302
0
            continue;
4303
0
        }
4304
15.0k
        assert(PyType_Check(obj));
4305
4306
15.0k
        if (PyList_Append(list, obj) < 0) {
  Branch (4306:13): [True: 0, False: 15.0k]
4307
0
            Py_DECREF(list);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
4308
0
            return NULL;
4309
0
        }
4310
15.0k
    }
4311
3.98k
    return list;
4312
3.98k
}
4313
4314
4315
/*[clinic input]
4316
type.__subclasses__
4317
4318
Return a list of immediate subclasses.
4319
[clinic start generated code]*/
4320
4321
static PyObject *
4322
type___subclasses___impl(PyTypeObject *self)
4323
/*[clinic end generated code: output=eb5eb54485942819 input=5af66132436f9a7b]*/
4324
18.6k
{
4325
18.6k
    return _PyType_GetSubclasses(self);
4326
18.6k
}
4327
4328
static PyObject *
4329
type_prepare(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
4330
             PyObject *kwnames)
4331
61.3k
{
4332
61.3k
    return PyDict_New();
4333
61.3k
}
4334
4335
4336
/*
4337
   Merge the __dict__ of aclass into dict, and recursively also all
4338
   the __dict__s of aclass's base classes.  The order of merging isn't
4339
   defined, as it's expected that only the final set of dict keys is
4340
   interesting.
4341
   Return 0 on success, -1 on error.
4342
*/
4343
4344
static int
4345
merge_class_dict(PyObject *dict, PyObject *aclass)
4346
57.5k
{
4347
57.5k
    PyObject *classdict;
4348
57.5k
    PyObject *bases;
4349
4350
57.5k
    assert(PyDict_Check(dict));
4351
57.5k
    assert(aclass);
4352
4353
    /* Merge in the type's dict (if any). */
4354
57.5k
    if (_PyObject_LookupAttr(aclass, &_Py_ID(__dict__), &classdict) < 0) {
Line
Count
Source
374
57.5k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
57.5k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
57.5k
    _PyRuntime.global_objects.NAME
  Branch (4354:9): [True: 0, False: 57.5k]
4355
0
        return -1;
4356
0
    }
4357
57.5k
    if (classdict != NULL) {
  Branch (4357:9): [True: 57.5k, False: 0]
4358
57.5k
        int status = PyDict_Update(dict, classdict);
4359
57.5k
        Py_DECREF(classdict);
Line
Count
Source
548
57.5k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
57.5k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
57.5k
#  define _Py_CAST(type, expr) ((type)(expr))
4360
57.5k
        if (status < 0)
  Branch (4360:13): [True: 0, False: 57.5k]
4361
0
            return -1;
4362
57.5k
    }
4363
4364
    /* Recursively merge in the base types' (if any) dicts. */
4365
57.5k
    if (_PyObject_LookupAttr(aclass, &_Py_ID(__bases__), &bases) < 0) {
Line
Count
Source
374
57.5k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
57.5k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
57.5k
    _PyRuntime.global_objects.NAME
  Branch (4365:9): [True: 0, False: 57.5k]
4366
0
        return -1;
4367
0
    }
4368
57.5k
    if (bases != NULL) {
  Branch (4368:9): [True: 57.5k, False: 0]
4369
        /* We have no guarantee that bases is a real tuple */
4370
57.5k
        Py_ssize_t i, n;
4371
57.5k
        n = PySequence_Size(bases); /* This better be right */
4372
57.5k
        if (n < 0) {
  Branch (4372:13): [True: 0, False: 57.5k]
4373
0
            Py_DECREF(bases);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
4374
0
            return -1;
4375
0
        }
4376
57.5k
        else {
4377
97.0k
            for (i = 0; i < n; i++) {
  Branch (4377:25): [True: 39.4k, False: 57.5k]
4378
39.4k
                int status;
4379
39.4k
                PyObject *base = PySequence_GetItem(bases, i);
4380
39.4k
                if (base == NULL) {
  Branch (4380:21): [True: 0, False: 39.4k]
4381
0
                    Py_DECREF(bases);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
4382
0
                    return -1;
4383
0
                }
4384
39.4k
                status = merge_class_dict(dict, base);
4385
39.4k
                Py_DECREF(base);
Line
Count
Source
548
39.4k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
39.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
39.4k
#  define _Py_CAST(type, expr) ((type)(expr))
4386
39.4k
                if (status < 0) {
  Branch (4386:21): [True: 0, False: 39.4k]
4387
0
                    Py_DECREF(bases);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
4388
0
                    return -1;
4389
0
                }
4390
39.4k
            }
4391
57.5k
        }
4392
57.5k
        Py_DECREF(bases);
Line
Count
Source
548
57.5k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
57.5k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
57.5k
#  define _Py_CAST(type, expr) ((type)(expr))
4393
57.5k
    }
4394
57.5k
    return 0;
4395
57.5k
}
4396
4397
/* __dir__ for type objects: returns __dict__ and __bases__.
4398
   We deliberately don't suck up its __class__, as methods belonging to the
4399
   metaclass would probably be more confusing than helpful.
4400
*/
4401
/*[clinic input]
4402
type.__dir__
4403
4404
Specialized __dir__ implementation for types.
4405
[clinic start generated code]*/
4406
4407
static PyObject *
4408
type___dir___impl(PyTypeObject *self)
4409
/*[clinic end generated code: output=69d02fe92c0f15fa input=7733befbec645968]*/
4410
6.68k
{
4411
6.68k
    PyObject *result = NULL;
4412
6.68k
    PyObject *dict = PyDict_New();
4413
4414
6.68k
    if (dict != NULL && merge_class_dict(dict, (PyObject *)self) == 0)
  Branch (4414:9): [True: 6.68k, False: 0]
  Branch (4414:25): [True: 6.68k, False: 0]
4415
6.68k
        result = PyDict_Keys(dict);
4416
4417
6.68k
    Py_XDECREF(dict);
Line
Count
Source
613
6.68k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
6.68k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6.68k
#  define _Py_CAST(type, expr) ((type)(expr))
4418
6.68k
    return result;
4419
6.68k
}
4420
4421
/*[clinic input]
4422
type.__sizeof__
4423
4424
Return memory consumption of the type object.
4425
[clinic start generated code]*/
4426
4427
static PyObject *
4428
type___sizeof___impl(PyTypeObject *self)
4429
/*[clinic end generated code: output=766f4f16cd3b1854 input=99398f24b9cf45d6]*/
4430
3
{
4431
3
    Py_ssize_t size;
4432
3
    if (self->tp_flags & Py_TPFLAGS_HEAPTYPE) {
Line
Count
Source
375
3
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (4432:9): [True: 2, False: 1]
4433
2
        PyHeapTypeObject* et = (PyHeapTypeObject*)self;
4434
2
        size = sizeof(PyHeapTypeObject);
4435
2
        if (et->ht_cached_keys)
  Branch (4435:13): [True: 2, False: 0]
4436
2
            size += _PyDict_KeysSize(et->ht_cached_keys);
4437
2
    }
4438
1
    else
4439
1
        size = sizeof(PyTypeObject);
4440
3
    return PyLong_FromSsize_t(size);
4441
3
}
4442
4443
static PyMethodDef type_methods[] = {
4444
    TYPE_MRO_METHODDEF
4445
    TYPE___SUBCLASSES___METHODDEF
4446
    {"__prepare__", _PyCFunction_CAST(type_prepare),
4447
     METH_FASTCALL | METH_KEYWORDS | METH_CLASS,
4448
     PyDoc_STR("__prepare__() -> dict\n"
4449
               "used to create the namespace for the class statement")},
4450
    TYPE___INSTANCECHECK___METHODDEF
4451
    TYPE___SUBCLASSCHECK___METHODDEF
4452
    TYPE___DIR___METHODDEF
4453
    TYPE___SIZEOF___METHODDEF
4454
    {0}
4455
};
4456
4457
PyDoc_STRVAR(type_doc,
4458
"type(object) -> the object's type\n"
4459
"type(name, bases, dict, **kwds) -> a new type");
4460
4461
static int
4462
type_traverse(PyTypeObject *type, visitproc visit, void *arg)
4463
184M
{
4464
    /* Because of type_is_gc(), the collector only calls this
4465
       for heaptypes. */
4466
184M
    if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
Line
Count
Source
375
184M
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (4466:9): [True: 0, False: 184M]
4467
0
        char msg[200];
4468
0
        sprintf(msg, "type_traverse() called on non-heap type '%.100s'",
4469
0
                type->tp_name);
4470
0
        _PyObject_ASSERT_FAILED_MSG((PyObject *)type, msg);
Line
Count
Source
393
0
    _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
4471
0
    }
4472
4473
184M
    Py_VISIT(type->tp_dict);
Line
Count
Source
198
184M
    do {                                                                \
199
184M
        if (op) {                                                       \
  Branch (199:13): [True: 184M, False: 2]
200
184M
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
184M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
184M
#  define _Py_CAST(type, expr) ((type)(expr))
201
184M
            if (vret)                                                   \
  Branch (201:17): [True: 3, False: 184M]
202
184M
                return vret;                                            \
203
184M
        }                                                               \
204
184M
    } while (0)
  Branch (204:14): [Folded - Ignored]
4474
184M
    Py_VISIT(type->tp_cache);
Line
Count
Source
198
184M
    do {                                                                \
199
184M
        if (op) {                                                       \
  Branch (199:13): [True: 0, False: 184M]
200
0
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
201
0
            if (vret)                                                   \
  Branch (201:17): [True: 0, False: 0]
202
0
                return vret;                                            \
203
0
        }                                                               \
204
184M
    } while (0)
  Branch (204:14): [Folded - Ignored]
4475
184M
    Py_VISIT(type->tp_mro);
Line
Count
Source
198
184M
    do {                                                                \
199
184M
        if (op) {                                                       \
  Branch (199:13): [True: 184M, False: 48]
200
184M
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
184M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
184M
#  define _Py_CAST(type, expr) ((type)(expr))
201
184M
            if (vret)                                                   \
  Branch (201:17): [True: 0, False: 184M]
202
184M
                return vret;                                            \
203
184M
        }                                                               \
204
184M
    } while (0)
  Branch (204:14): [Folded - Ignored]
4476
184M
    Py_VISIT(type->tp_bases);
Line
Count
Source
198
184M
    do {                                                                \
199
184M
        if (op) {                                                       \
  Branch (199:13): [True: 184M, False: 0]
200
184M
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
184M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
184M
#  define _Py_CAST(type, expr) ((type)(expr))
201
184M
            if (vret)                                                   \
  Branch (201:17): [True: 0, False: 184M]
202
184M
                return vret;                                            \
203
184M
        }                                                               \
204
184M
    } while (0)
  Branch (204:14): [Folded - Ignored]
4477
184M
    Py_VISIT(type->tp_base);
Line
Count
Source
198
184M
    do {                                                                \
199
184M
        if (op) {                                                       \
  Branch (199:13): [True: 184M, False: 0]
200
184M
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
184M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
184M
#  define _Py_CAST(type, expr) ((type)(expr))
201
184M
            if (vret)                                                   \
  Branch (201:17): [True: 0, False: 184M]
202
184M
                return vret;                                            \
203
184M
        }                                                               \
204
184M
    } while (0)
  Branch (204:14): [Folded - Ignored]
4478
184M
    Py_VISIT(((PyHeapTypeObject *)type)->ht_module);
Line
Count
Source
198
184M
    do {                                                                \
199
184M
        if (op) {                                                       \
  Branch (199:13): [True: 1.63M, False: 183M]
200
1.63M
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
1.63M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.63M
#  define _Py_CAST(type, expr) ((type)(expr))
201
1.63M
            if (vret)                                                   \
  Branch (201:17): [True: 0, False: 1.63M]
202
1.63M
                return vret;                                            \
203
1.63M
        }                                                               \
204
184M
    } while (0)
  Branch (204:14): [Folded - Ignored]
4479
4480
    /* There's no need to visit others because they can't be involved
4481
       in cycles:
4482
       type->tp_subclasses is a list of weak references,
4483
       ((PyHeapTypeObject *)type)->ht_slots is a tuple of strings,
4484
       ((PyHeapTypeObject *)type)->ht_*name are strings.
4485
       */
4486
4487
184M
    return 0;
4488
184M
}
4489
4490
static int
4491
type_clear(PyTypeObject *type)
4492
91.2k
{
4493
    /* Because of type_is_gc(), the collector only calls this
4494
       for heaptypes. */
4495
91.2k
    _PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE);
Line
Count
Source
390
91.2k
    _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
Line
Count
Source
388
91.2k
    _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
Line
Count
Source
377
91.2k
    ((void)0)
4496
4497
    /* We need to invalidate the method cache carefully before clearing
4498
       the dict, so that other objects caught in a reference cycle
4499
       don't start calling destroyed methods.
4500
4501
       Otherwise, the we need to clear tp_mro, which is
4502
       part of a hard cycle (its first element is the class itself) that
4503
       won't be broken otherwise (it's a tuple and tuples don't have a
4504
       tp_clear handler).
4505
       We also need to clear ht_module, if present: the module usually holds a
4506
       reference to its class. None of the other fields need to be
4507
4508
       cleared, and here's why:
4509
4510
       tp_cache:
4511
           Not used; if it were, it would be a dict.
4512
4513
       tp_bases, tp_base:
4514
           If these are involved in a cycle, there must be at least
4515
           one other, mutable object in the cycle, e.g. a base
4516
           class's dict; the cycle will be broken that way.
4517
4518
       tp_subclasses:
4519
           A dict of weak references can't be part of a cycle; and
4520
           dicts have their own tp_clear.
4521
4522
       slots (in PyHeapTypeObject):
4523
           A tuple of strings can't be part of a cycle.
4524
    */
4525
4526
91.2k
    PyType_Modified(type);
4527
91.2k
    if (type->tp_dict) {
  Branch (4527:9): [True: 91.2k, False: 0]
4528
91.2k
        PyDict_Clear(type->tp_dict);
4529
91.2k
    }
4530
91.2k
    Py_CLEAR(((PyHeapTypeObject *)type)->ht_module);
Line
Count
Source
587
91.2k
    do {                                        \
588
91.2k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
589
91.2k
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 1.96k, False: 89.2k]
590
1.96k
            (op) = NULL;                        \
591
1.96k
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
1.96k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1.96k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.96k
#  define _Py_CAST(type, expr) ((type)(expr))
592
1.96k
        }                                       \
593
91.2k
    } while (0)
  Branch (593:14): [Folded - Ignored]
4531
4532
91.2k
    Py_CLEAR(type->tp_mro);
Line
Count
Source
587
91.2k
    do {                                        \
588
91.2k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
589
91.2k
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 91.2k, False: 0]
590
91.2k
            (op) = NULL;                        \
591
91.2k
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
91.2k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
91.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91.2k
#  define _Py_CAST(type, expr) ((type)(expr))
592
91.2k
        }                                       \
593
91.2k
    } while (0)
  Branch (593:14): [Folded - Ignored]
4533
4534
91.2k
    return 0;
4535
91.2k
}
4536
4537
static int
4538
type_is_gc(PyTypeObject *type)
4539
2.21G
{
4540
2.21G
    return type->tp_flags & Py_TPFLAGS_HEAPTYPE;
Line
Count
Source
375
2.21G
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
4541
2.21G
}
4542
4543
4544
static PyNumberMethods type_as_number = {
4545
        .nb_or = _Py_union_type_or, // Add __or__ function
4546
};
4547
4548
PyTypeObject PyType_Type = {
4549
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
4550
    "type",                                     /* tp_name */
4551
    sizeof(PyHeapTypeObject),                   /* tp_basicsize */
4552
    sizeof(PyMemberDef),                        /* tp_itemsize */
4553
    (destructor)type_dealloc,                   /* tp_dealloc */
4554
    offsetof(PyTypeObject, tp_vectorcall),      /* tp_vectorcall_offset */
4555
    0,                                          /* tp_getattr */
4556
    0,                                          /* tp_setattr */
4557
    0,                                          /* tp_as_async */
4558
    (reprfunc)type_repr,                        /* tp_repr */
4559
    &type_as_number,                            /* tp_as_number */
4560
    0,                                          /* tp_as_sequence */
4561
    0,                                          /* tp_as_mapping */
4562
    0,                                          /* tp_hash */
4563
    (ternaryfunc)type_call,                     /* tp_call */
4564
    0,                                          /* tp_str */
4565
    (getattrofunc)type_getattro,                /* tp_getattro */
4566
    (setattrofunc)type_setattro,                /* tp_setattro */
4567
    0,                                          /* tp_as_buffer */
4568
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
4569
    Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TYPE_SUBCLASS |
4570
    Py_TPFLAGS_HAVE_VECTORCALL,                 /* tp_flags */
4571
    type_doc,                                   /* tp_doc */
4572
    (traverseproc)type_traverse,                /* tp_traverse */
4573
    (inquiry)type_clear,                        /* tp_clear */
4574
    0,                                          /* tp_richcompare */
4575
    offsetof(PyTypeObject, tp_weaklist),        /* tp_weaklistoffset */
4576
    0,                                          /* tp_iter */
4577
    0,                                          /* tp_iternext */
4578
    type_methods,                               /* tp_methods */
4579
    type_members,                               /* tp_members */
4580
    type_getsets,                               /* tp_getset */
4581
    0,                                          /* tp_base */
4582
    0,                                          /* tp_dict */
4583
    0,                                          /* tp_descr_get */
4584
    0,                                          /* tp_descr_set */
4585
    offsetof(PyTypeObject, tp_dict),            /* tp_dictoffset */
4586
    type_init,                                  /* tp_init */
4587
    0,                                          /* tp_alloc */
4588
    type_new,                                   /* tp_new */
4589
    PyObject_GC_Del,                            /* tp_free */
4590
    (inquiry)type_is_gc,                        /* tp_is_gc */
4591
    .tp_vectorcall = type_vectorcall,
4592
};
4593
4594
4595
/* The base type of all types (eventually)... except itself. */
4596
4597
/* You may wonder why object.__new__() only complains about arguments
4598
   when object.__init__() is not overridden, and vice versa.
4599
4600
   Consider the use cases:
4601
4602
   1. When neither is overridden, we want to hear complaints about
4603
      excess (i.e., any) arguments, since their presence could
4604
      indicate there's a bug.
4605
4606
   2. When defining an Immutable type, we are likely to override only
4607
      __new__(), since __init__() is called too late to initialize an
4608
      Immutable object.  Since __new__() defines the signature for the
4609
      type, it would be a pain to have to override __init__() just to
4610
      stop it from complaining about excess arguments.
4611
4612
   3. When defining a Mutable type, we are likely to override only
4613
      __init__().  So here the converse reasoning applies: we don't
4614
      want to have to override __new__() just to stop it from
4615
      complaining.
4616
4617
   4. When __init__() is overridden, and the subclass __init__() calls
4618
      object.__init__(), the latter should complain about excess
4619
      arguments; ditto for __new__().
4620
4621
   Use cases 2 and 3 make it unattractive to unconditionally check for
4622
   excess arguments.  The best solution that addresses all four use
4623
   cases is as follows: __init__() complains about excess arguments
4624
   unless __new__() is overridden and __init__() is not overridden
4625
   (IOW, if __init__() is overridden or __new__() is not overridden);
4626
   symmetrically, __new__() complains about excess arguments unless
4627
   __init__() is overridden and __new__() is not overridden
4628
   (IOW, if __new__() is overridden or __init__() is not overridden).
4629
4630
   However, for backwards compatibility, this breaks too much code.
4631
   Therefore, in 2.6, we'll *warn* about excess arguments when both
4632
   methods are overridden; for all other cases we'll use the above
4633
   rules.
4634
4635
*/
4636
4637
/* Forward */
4638
static PyObject *
4639
object_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
4640
4641
static int
4642
excess_args(PyObject *args, PyObject *kwds)
4643
21.1M
{
4644
21.1M
    return PyTuple_GET_SIZE(args) ||
Line
Count
Source
26
42.3M
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
21.1M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21.1M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (26:30): [True: 14.3M, False: 6.82M]
4645
21.1M
        (kwds && PyDict_Check(kwds) && PyDict_GET_SIZE(kwds));
Line
Count
Source
18
746k
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
Line
Count
Source
782
7.57M
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 746k, False: 0]
        (kwds && PyDict_Check(kwds) && PyDict_GET_SIZE(kwds));
Line
Count
Source
55
746k
#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
746k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
746k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (55:29): [True: 122k, False: 624k]
  Branch (4645:10): [True: 746k, False: 6.08M]
4646
21.1M
}
4647
4648
static int
4649
object_init(PyObject *self, PyObject *args, PyObject *kwds)
4650
10.9M
{
4651
10.9M
    PyTypeObject *type = Py_TYPE(self);
Line
Count
Source
138
10.9M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10.9M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10.9M
#  define _Py_CAST(type, expr) ((type)(expr))
4652
10.9M
    if (excess_args(args, kwds)) {
  Branch (4652:9): [True: 9.44M, False: 1.47M]
4653
9.44M
        if (type->tp_init != object_init) {
  Branch (4653:13): [True: 5, False: 9.44M]
4654
5
            PyErr_SetString(PyExc_TypeError,
4655
5
                            "object.__init__() takes exactly one argument (the instance to initialize)");
4656
5
            return -1;
4657
5
        }
4658
9.44M
        if (type->tp_new == object_new) {
  Branch (4658:13): [True: 3, False: 9.44M]
4659
3
            PyErr_Format(PyExc_TypeError,
4660
3
                         "%.200s.__init__() takes exactly one argument (the instance to initialize)",
4661
3
                         type->tp_name);
4662
3
            return -1;
4663
3
        }
4664
9.44M
    }
4665
10.9M
    return 0;
4666
10.9M
}
4667
4668
static PyObject *
4669
object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4670
10.2M
{
4671
10.2M
    if (excess_args(args, kwds)) {
  Branch (4671:9): [True: 5.03M, False: 5.22M]
4672
5.03M
        if (type->tp_new != object_new) {
  Branch (4672:13): [True: 9, False: 5.03M]
4673
9
            PyErr_SetString(PyExc_TypeError,
4674
9
                            "object.__new__() takes exactly one argument (the type to instantiate)");
4675
9
            return NULL;
4676
9
        }
4677
5.03M
        if (type->tp_init == object_init) {
  Branch (4677:13): [True: 57, False: 5.03M]
4678
57
            PyErr_Format(PyExc_TypeError, "%.200s() takes no arguments",
4679
57
                         type->tp_name);
4680
57
            return NULL;
4681
57
        }
4682
5.03M
    }
4683
4684
10.2M
    if (type->tp_flags & Py_TPFLAGS_IS_ABSTRACT) {
Line
Count
Source
410
10.2M
#define Py_TPFLAGS_IS_ABSTRACT (1UL << 20)
  Branch (4684:9): [True: 80, False: 10.2M]
4685
80
        PyObject *abstract_methods;
4686
80
        PyObject *sorted_methods;
4687
80
        PyObject *joined;
4688
80
        Py_ssize_t method_count;
4689
4690
        /* Compute ", ".join(sorted(type.__abstractmethods__))
4691
           into joined. */
4692
80
        abstract_methods = type_abstractmethods(type, NULL);
4693
80
        if (abstract_methods == NULL)
  Branch (4693:13): [True: 0, False: 80]
4694
0
            return NULL;
4695
80
        sorted_methods = PySequence_List(abstract_methods);
4696
80
        Py_DECREF(abstract_methods);
Line
Count
Source
548
80
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
80
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
80
#  define _Py_CAST(type, expr) ((type)(expr))
4697
80
        if (sorted_methods == NULL)
  Branch (4697:13): [True: 0, False: 80]
4698
0
            return NULL;
4699
80
        if (PyList_Sort(sorted_methods)) {
  Branch (4699:13): [True: 0, False: 80]
4700
0
            Py_DECREF(sorted_methods);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
4701
0
            return NULL;
4702
0
        }
4703
80
        _Py_DECLARE_STR(comma_sep, ", ");
4704
80
        joined = PyUnicode_Join(&_Py_STR(comma_sep), sorted_methods);
Line
Count
Source
376
80
     (_Py_SINGLETON(strings.literals._ ## NAME._ascii.ob_base))
Line
Count
Source
26
80
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
80
    _PyRuntime.global_objects.NAME
4705
80
        method_count = PyObject_Length(sorted_methods);
Line
Count
Source
283
80
#define PyObject_Length PyObject_Size
4706
80
        Py_DECREF(sorted_methods);
Line
Count
Source
548
80
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
80
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
80
#  define _Py_CAST(type, expr) ((type)(expr))
4707
80
        if (joined == NULL)
  Branch (4707:13): [True: 0, False: 80]
4708
0
            return NULL;
4709
80
        if (method_count == -1)
  Branch (4709:13): [True: 0, False: 80]
4710
0
            return NULL;
4711
4712
80
        PyErr_Format(PyExc_TypeError,
4713
80
                     "Can't instantiate abstract class %s "
4714
80
                     "without an implementation for abstract method%s %U",
4715
80
                     type->tp_name,
4716
80
                     method_count > 1 ? "s" : "",
  Branch (4716:22): [True: 12, False: 68]
4717
80
                     joined);
4718
80
        Py_DECREF(joined);
Line
Count
Source
548
80
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
80
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
80
#  define _Py_CAST(type, expr) ((type)(expr))
4719
80
        return NULL;
4720
80
    }
4721
10.2M
    PyObject *obj = type->tp_alloc(type, 0);
4722
10.2M
    if (obj == NULL) {
  Branch (4722:9): [True: 0, False: 10.2M]
4723
0
        return NULL;
4724
0
    }
4725
10.2M
    if (_PyObject_InitializeDict(obj)) {
  Branch (4725:9): [True: 0, False: 10.2M]
4726
0
        Py_DECREF(obj);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
4727
0
        return NULL;
4728
0
    }
4729
10.2M
    return obj;
4730
10.2M
}
4731
4732
static void
4733
object_dealloc(PyObject *self)
4734
162M
{
4735
162M
    Py_TYPE(self)->tp_free(self);
Line
Count
Source
138
162M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
162M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
162M
#  define _Py_CAST(type, expr) ((type)(expr))
4736
162M
}
4737
4738
static PyObject *
4739
object_repr(PyObject *self)
4740
3.91k
{
4741
3.91k
    PyTypeObject *type;
4742
3.91k
    PyObject *mod, *name, *rtn;
4743
4744
3.91k
    type = Py_TYPE(self);
Line
Count
Source
138
3.91k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3.91k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.91k
#  define _Py_CAST(type, expr) ((type)(expr))
4745
3.91k
    mod = type_module(type, NULL);
4746
3.91k
    if (mod == NULL)
  Branch (4746:9): [True: 0, False: 3.91k]
4747
0
        PyErr_Clear();
4748
3.91k
    else if (!PyUnicode_Check(mod)) {
Line
Count
Source
115
3.91k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
3.91k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (4748:14): [True: 0, False: 3.91k]
4749
0
        Py_DECREF(mod);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
4750
0
        mod = NULL;
4751
0
    }
4752
3.91k
    name = type_qualname(type, NULL);
4753
3.91k
    if (name == NULL) {
  Branch (4753:9): [True: 0, False: 3.91k]
4754
0
        Py_XDECREF(mod);
Line
Count
Source
613
0
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
4755
0
        return NULL;
4756
0
    }
4757
3.91k
    if (mod != NULL && !_PyUnicode_Equal(mod, &_Py_ID(builtins)))
Line
Count
Source
374
3.91k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
3.91k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
3.91k
    _PyRuntime.global_objects.NAME
  Branch (4757:9): [True: 3.91k, False: 0]
  Branch (4757:24): [True: 3.79k, False: 123]
4758
3.79k
        rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, name, self);
4759
123
    else
4760
123
        rtn = PyUnicode_FromFormat("<%s object at %p>",
4761
123
                                  type->tp_name, self);
4762
3.91k
    Py_XDECREF(mod);
Line
Count
Source
613
3.91k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.91k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.91k
#  define _Py_CAST(type, expr) ((type)(expr))
4763
3.91k
    Py_DECREF(name);
Line
Count
Source
548
3.91k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.91k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.91k
#  define _Py_CAST(type, expr) ((type)(expr))
4764
3.91k
    return rtn;
4765
3.91k
}
4766
4767
static PyObject *
4768
object_str(PyObject *self)
4769
738k
{
4770
738k
    unaryfunc f;
4771
4772
738k
    f = Py_TYPE(self)->tp_repr;
Line
Count
Source
138
738k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
738k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
738k
#  define _Py_CAST(type, expr) ((type)(expr))
4773
738k
    if (f == NULL)
  Branch (4773:9): [True: 0, False: 738k]
4774
0
        f = object_repr;
4775
738k
    return f(self);
4776
738k
}
4777
4778
static PyObject *
4779
object_richcompare(PyObject *self, PyObject *other, int op)
4780
8.05M
{
4781
8.05M
    PyObject *res;
4782
4783
8.05M
    switch (op) {
4784
4785
8.02M
    case Py_EQ:
Line
Count
Source
676
8.02M
#define Py_EQ 2
  Branch (4785:5): [True: 8.02M, False: 36.4k]
4786
        /* Return NotImplemented instead of False, so if two
4787
           objects are compared, both get a chance at the
4788
           comparison.  See issue #1393. */
4789
8.02M
        res = (self == other) ? Py_True : Py_NotImplemented;
Line
Count
Source
23
8.02M
#define Py_True _PyObject_CAST(&_Py_TrueStruct)
Line
Count
Source
109
660k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
660k
#  define _Py_CAST(type, expr) ((type)(expr))
        res = (self == other) ? Py_True : Py_NotImplemented;
Line
Count
Source
668
15.3M
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (4789:15): [True: 660k, False: 7.35M]
4790
8.02M
        Py_INCREF(res);
Line
Count
Source
512
8.02M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
8.02M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8.02M
#  define _Py_CAST(type, expr) ((type)(expr))
4791
8.02M
        break;
4792
4793
34.4k
    case Py_NE:
Line
Count
Source
677
34.4k
#define Py_NE 3
  Branch (4793:5): [True: 34.4k, False: 8.02M]
4794
        /* By default, __ne__() delegates to __eq__() and inverts the result,
4795
           unless the latter returns NotImplemented. */
4796
34.4k
        if (Py_TYPE(self)->tp_richcompare == NULL) {
Line
Count
Source
138
34.4k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
34.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
34.4k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (4796:13): [True: 0, False: 34.4k]
4797
0
            res = Py_NotImplemented;
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
4798
0
            Py_INCREF(res);
Line
Count
Source
512
0
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
4799
0
            break;
4800
0
        }
4801
34.4k
        res = (*Py_TYPE(self)->tp_richcompare)(self, other, Py_EQ);
Line
Count
Source
138
34.4k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
34.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
34.4k
#  define _Py_CAST(type, expr) ((type)(expr))
        res = (*Py_TYPE(self)->tp_richcompare)(self, other, Py_EQ);
Line
Count
Source
676
34.4k
#define Py_EQ 2
4802
34.4k
        if (res != NULL && res != Py_NotImplemented) {
Line
Count
Source
668
34.4k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (4802:13): [True: 34.4k, False: 16]
  Branch (4802:28): [True: 13.0k, False: 21.3k]
4803
13.0k
            int ok = PyObject_IsTrue(res);
4804
13.0k
            Py_DECREF(res);
Line
Count
Source
548
13.0k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
13.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.0k
#  define _Py_CAST(type, expr) ((type)(expr))
4805
13.0k
            if (ok < 0)
  Branch (4805:17): [True: 0, False: 13.0k]
4806
0
                res = NULL;
4807
13.0k
            else {
4808
13.0k
                if (ok)
  Branch (4808:21): [True: 11.4k, False: 1.56k]
4809
11.4k
                    res = Py_False;
Line
Count
Source
22
11.4k
#define Py_False _PyObject_CAST(&_Py_FalseStruct)
Line
Count
Source
109
11.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11.4k
#  define _Py_CAST(type, expr) ((type)(expr))
4810
1.56k
                else
4811
1.56k
                    res = Py_True;
Line
Count
Source
23
1.56k
#define Py_True _PyObject_CAST(&_Py_TrueStruct)
Line
Count
Source
109
1.56k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.56k
#  define _Py_CAST(type, expr) ((type)(expr))
4812
13.0k
                Py_INCREF(res);
Line
Count
Source
512
13.0k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
13.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.0k
#  define _Py_CAST(type, expr) ((type)(expr))
4813
13.0k
            }
4814
13.0k
        }
4815
34.4k
        break;
4816
4817
2.03k
    default:
  Branch (4817:5): [True: 2.03k, False: 8.05M]
4818
2.03k
        res = Py_NotImplemented;
Line
Count
Source
668
2.03k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
4819
2.03k
        Py_INCREF(res);
Line
Count
Source
512
2.03k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
2.03k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.03k
#  define _Py_CAST(type, expr) ((type)(expr))
4820
2.03k
        break;
4821
8.05M
    }
4822
4823
8.05M
    return res;
4824
8.05M
}
4825
4826
static PyObject *
4827
object_get_class(PyObject *self, void *closure)
4828
15.8M
{
4829
15.8M
    Py_INCREF(Py_TYPE(self));
Line
Count
Source
512
15.8M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
15.8M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
15.8M
#  define _Py_CAST(type, expr) ((type)(expr))
4830
15.8M
    return (PyObject *)(Py_TYPE(self));
Line
Count
Source
138
15.8M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
15.8M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
15.8M
#  define _Py_CAST(type, expr) ((type)(expr))
4831
15.8M
}
4832
4833
static int
4834
compatible_with_tp_base(PyTypeObject *child)
4835
858
{
4836
858
    PyTypeObject *parent = child->tp_base;
4837
858
    return (parent != NULL &&
  Branch (4837:13): [True: 828, False: 30]
4838
858
            child->tp_basicsize == parent->tp_basicsize &&
  Branch (4838:13): [True: 144, False: 684]
4839
858
            child->tp_itemsize == parent->tp_itemsize &&
  Branch (4839:13): [True: 144, False: 0]
4840
858
            child->tp_dictoffset == parent->tp_dictoffset &&
  Branch (4840:13): [True: 128, False: 16]
4841
858
            child->tp_weaklistoffset == parent->tp_weaklistoffset &&
  Branch (4841:13): [True: 128, False: 0]
4842
858
            ((child->tp_flags & Py_TPFLAGS_HAVE_GC) ==
Line
Count
Source
394
128
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (4842:13): [True: 112, False: 16]
4843
128
             (parent->tp_flags & Py_TPFLAGS_HAVE_GC)) &&
Line
Count
Source
394
128
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
4844
858
            (child->tp_dealloc == subtype_dealloc ||
  Branch (4844:14): [True: 112, False: 0]
4845
112
             child->tp_dealloc == parent->tp_dealloc));
  Branch (4845:14): [True: 0, False: 0]
4846
858
}
4847
4848
static int
4849
same_slots_added(PyTypeObject *a, PyTypeObject *b)
4850
151
{
4851
151
    PyTypeObject *base = a->tp_base;
4852
151
    Py_ssize_t size;
4853
151
    PyObject *slots_a, *slots_b;
4854
4855
151
    assert(base == b->tp_base);
4856
151
    size = base->tp_basicsize;
4857
151
    if (a->tp_dictoffset == size && b->tp_dictoffset == size)
  Branch (4857:9): [True: 0, False: 151]
  Branch (4857:37): [True: 0, False: 0]
4858
0
        size += sizeof(PyObject *);
4859
151
    if (a->tp_weaklistoffset == size && b->tp_weaklistoffset == size)
  Branch (4859:9): [True: 135, False: 16]
  Branch (4859:41): [True: 133, False: 2]
4860
133
        size += sizeof(PyObject *);
4861
4862
    /* Check slots compliance */
4863
151
    if (!(a->tp_flags & Py_TPFLAGS_HEAPTYPE) ||
Line
Count
Source
375
151
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (4863:9): [True: 2, False: 149]
4864
151
        !(b->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
Line
Count
Source
375
149
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (4864:9): [True: 0, False: 149]
4865
2
        return 0;
4866
2
    }
4867
149
    slots_a = ((PyHeapTypeObject *)a)->ht_slots;
4868
149
    slots_b = ((PyHeapTypeObject *)b)->ht_slots;
4869
149
    if (slots_a && slots_b) {
  Branch (4869:9): [True: 20, False: 129]
  Branch (4869:20): [True: 18, False: 2]
4870
18
        if (PyObject_RichCompareBool(slots_a, slots_b, Py_EQ) != 1)
Line
Count
Source
676
18
#define Py_EQ 2
  Branch (4870:13): [True: 6, False: 12]
4871
6
            return 0;
4872
12
        size += sizeof(PyObject *) * PyTuple_GET_SIZE(slots_a);
Line
Count
Source
26
12
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
4873
12
    }
4874
143
    return size == a->tp_basicsize && size == b->tp_basicsize;
  Branch (4874:12): [True: 141, False: 2]
  Branch (4874:39): [True: 139, False: 2]
4875
149
}
4876
4877
static int
4878
compatible_for_assignment(PyTypeObject* oldto, PyTypeObject* newto, const char* attr)
4879
373
{
4880
373
    PyTypeObject *newbase, *oldbase;
4881
4882
373
    if (newto->tp_free != oldto->tp_free) {
  Branch (4882:9): [True: 0, False: 373]
4883
0
        PyErr_Format(PyExc_TypeError,
4884
0
                     "%s assignment: "
4885
0
                     "'%s' deallocator differs from '%s'",
4886
0
                     attr,
4887
0
                     newto->tp_name,
4888
0
                     oldto->tp_name);
4889
0
        return 0;
4890
0
    }
4891
    /*
4892
     It's tricky to tell if two arbitrary types are sufficiently compatible as
4893
     to be interchangeable; e.g., even if they have the same tp_basicsize, they
4894
     might have totally different struct fields. It's much easier to tell if a
4895
     type and its supertype are compatible; e.g., if they have the same
4896
     tp_basicsize, then that means they have identical fields. So to check
4897
     whether two arbitrary types are compatible, we first find the highest
4898
     supertype that each is compatible with, and then if those supertypes are
4899
     compatible then the original types must also be compatible.
4900
    */
4901
373
    newbase = newto;
4902
373
    oldbase = oldto;
4903
462
    while (compatible_with_tp_base(newbase))
  Branch (4903:12): [True: 89, False: 373]
4904
89
        newbase = newbase->tp_base;
4905
396
    while (compatible_with_tp_base(oldbase))
  Branch (4905:12): [True: 23, False: 373]
4906
23
        oldbase = oldbase->tp_base;
4907
373
    if (newbase != oldbase &&
  Branch (4907:9): [True: 211, False: 162]
4908
373
        (newbase->tp_base != oldbase->tp_base ||
  Branch (4908:10): [True: 60, False: 151]
4909
211
         !same_slots_added(newbase, oldbase))) {
  Branch (4909:10): [True: 12, False: 139]
4910
72
        goto differs;
4911
72
    }
4912
    /* The above does not check for managed __dicts__ */
4913
301
    if ((oldto->tp_flags & Py_TPFLAGS_MANAGED_DICT) ==
Line
Count
Source
359
301
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
  Branch (4913:9): [True: 299, False: 2]
4914
301
        ((newto->tp_flags & Py_TPFLAGS_MANAGED_DICT)))
Line
Count
Source
359
301
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
4915
299
    {
4916
299
        return 1;
4917
299
    }
4918
74
differs:
4919
74
    PyErr_Format(PyExc_TypeError,
4920
74
                    "%s assignment: "
4921
74
                    "'%s' object layout differs from '%s'",
4922
74
                    attr,
4923
74
                    newto->tp_name,
4924
74
                    oldto->tp_name);
4925
74
    return 0;
4926
301
}
4927
4928
static int
4929
object_set_class(PyObject *self, PyObject *value, void *closure)
4930
455
{
4931
455
    PyTypeObject *oldto = Py_TYPE(self);
Line
Count
Source
138
455
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
455
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
455
#  define _Py_CAST(type, expr) ((type)(expr))
4932
4933
455
    if (value == NULL) {
  Branch (4933:9): [True: 101, False: 354]
4934
101
        PyErr_SetString(PyExc_TypeError,
4935
101
                        "can't delete __class__ attribute");
4936
101
        return -1;
4937
101
    }
4938
354
    if (!PyType_Check(value)) {
Line
Count
Source
788
354
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
354
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
354
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (4938:9): [True: 1, False: 353]
4939
1
        PyErr_Format(PyExc_TypeError,
4940
1
          "__class__ must be set to a class, not '%s' object",
4941
1
          Py_TYPE(value)->tp_name);
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
4942
1
        return -1;
4943
1
    }
4944
353
    PyTypeObject *newto = (PyTypeObject *)value;
4945
4946
353
    if (PySys_Audit("object.__setattr__", "OsO",
  Branch (4946:9): [True: 0, False: 353]
4947
353
                    self, "__class__", value) < 0) {
4948
0
        return -1;
4949
0
    }
4950
4951
    /* In versions of CPython prior to 3.5, the code in
4952
       compatible_for_assignment was not set up to correctly check for memory
4953
       layout / slot / etc. compatibility for non-HEAPTYPE classes, so we just
4954
       disallowed __class__ assignment in any case that wasn't HEAPTYPE ->
4955
       HEAPTYPE.
4956
4957
       During the 3.5 development cycle, we fixed the code in
4958
       compatible_for_assignment to correctly check compatibility between
4959
       arbitrary types, and started allowing __class__ assignment in all cases
4960
       where the old and new types did in fact have compatible slots and
4961
       memory layout (regardless of whether they were implemented as HEAPTYPEs
4962
       or not).
4963
4964
       Just before 3.5 was released, though, we discovered that this led to
4965
       problems with immutable types like int, where the interpreter assumes
4966
       they are immutable and interns some values. Formerly this wasn't a
4967
       problem, because they really were immutable -- in particular, all the
4968
       types where the interpreter applied this interning trick happened to
4969
       also be statically allocated, so the old HEAPTYPE rules were
4970
       "accidentally" stopping them from allowing __class__ assignment. But
4971
       with the changes to __class__ assignment, we started allowing code like
4972
4973
         class MyInt(int):
4974
             ...
4975
         # Modifies the type of *all* instances of 1 in the whole program,
4976
         # including future instances (!), because the 1 object is interned.
4977
         (1).__class__ = MyInt
4978
4979
       (see https://bugs.python.org/issue24912).
4980
4981
       In theory the proper fix would be to identify which classes rely on
4982
       this invariant and somehow disallow __class__ assignment only for them,
4983
       perhaps via some mechanism like a new Py_TPFLAGS_IMMUTABLE flag (a
4984
       "denylisting" approach). But in practice, since this problem wasn't
4985
       noticed late in the 3.5 RC cycle, we're taking the conservative
4986
       approach and reinstating the same HEAPTYPE->HEAPTYPE check that we used
4987
       to have, plus an "allowlist". For now, the allowlist consists only of
4988
       ModuleType subtypes, since those are the cases that motivated the patch
4989
       in the first place -- see https://bugs.python.org/issue22986 -- and
4990
       since module objects are mutable we can be sure that they are
4991
       definitely not being interned. So now we allow HEAPTYPE->HEAPTYPE *or*
4992
       ModuleType subtype -> ModuleType subtype.
4993
4994
       So far as we know, all the code beyond the following 'if' statement
4995
       will correctly handle non-HEAPTYPE classes, and the HEAPTYPE check is
4996
       needed only to protect that subset of non-HEAPTYPE classes for which
4997
       the interpreter has baked in the assumption that all instances are
4998
       truly immutable.
4999
    */
5000
353
    if (!(PyType_IsSubtype(newto, &PyModule_Type) &&
  Branch (5000:11): [True: 20, False: 333]
5001
353
          PyType_IsSubtype(oldto, &PyModule_Type)) &&
  Branch (5001:11): [True: 20, False: 0]
5002
353
        (_PyType_HasFeature(newto, Py_TPFLAGS_IMMUTABLETYPE) ||
Line
Count
Source
372
333
#define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
  Branch (5002:10): [True: 17, False: 316]
5003
333
         _PyType_HasFeature(oldto, Py_TPFLAGS_IMMUTABLETYPE))) {
Line
Count
Source
372
316
#define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
  Branch (5003:10): [True: 18, False: 298]
5004
35
        PyErr_Format(PyExc_TypeError,
5005
35
                     "__class__ assignment only supported for mutable types "
5006
35
                     "or ModuleType subclasses");
5007
35
        return -1;
5008
35
    }
5009
5010
318
    if (compatible_for_assignment(oldto, newto, "__class__")) {
  Branch (5010:9): [True: 246, False: 72]
5011
        /* Changing the class will change the implicit dict keys,
5012
         * so we must materialize the dictionary first. */
5013
246
        assert((oldto->tp_flags & Py_TPFLAGS_MANAGED_DICT) == (newto->tp_flags & Py_TPFLAGS_MANAGED_DICT));
5014
246
        _PyObject_GetDictPtr(self);
5015
246
        if (oldto->tp_flags & Py_TPFLAGS_MANAGED_DICT && *_PyObject_ValuesPointer(self)) {
Line
Count
Source
359
492
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
  Branch (5015:13): [True: 219, False: 27]
  Branch (5015:58): [True: 0, False: 219]
5016
            /* Was unable to convert to dict */
5017
0
            PyErr_NoMemory();
5018
0
            return -1;
5019
0
        }
5020
246
        if (newto->tp_flags & Py_TPFLAGS_HEAPTYPE) {
Line
Count
Source
375
246
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (5020:13): [True: 236, False: 10]
5021
236
            Py_INCREF(newto);
Line
Count
Source
512
236
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
236
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
236
#  define _Py_CAST(type, expr) ((type)(expr))
5022
236
        }
5023
246
        Py_SET_TYPE(self, newto);
Line
Count
Source
171
246
#  define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
Line
Count
Source
109
246
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
246
#  define _Py_CAST(type, expr) ((type)(expr))
5024
246
        if (oldto->tp_flags & Py_TPFLAGS_HEAPTYPE)
Line
Count
Source
375
246
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (5024:13): [True: 236, False: 10]
5025
236
            Py_DECREF(oldto);
Line
Count
Source
548
236
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
236
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
236
#  define _Py_CAST(type, expr) ((type)(expr))
5026
246
        return 0;
5027
246
    }
5028
72
    else {
5029
72
        return -1;
5030
72
    }
5031
318
}
5032
5033
static PyGetSetDef object_getsets[] = {
5034
    {"__class__", object_get_class, object_set_class,
5035
     PyDoc_STR("the object's class")},
5036
    {0}
5037
};
5038
5039
5040
/* Stuff to implement __reduce_ex__ for pickle protocols >= 2.
5041
   We fall back to helpers in copyreg for:
5042
   - pickle protocols < 2
5043
   - calculating the list of slot names (done only once per class)
5044
   - the __newobj__ function (which is used as a token but never called)
5045
*/
5046
5047
static PyObject *
5048
import_copyreg(void)
5049
81.9k
{
5050
    /* Try to fetch cached copy of copyreg from sys.modules first in an
5051
       attempt to avoid the import overhead. Previously this was implemented
5052
       by storing a reference to the cached module in a static variable, but
5053
       this broke when multiple embedded interpreters were in use (see issue
5054
       #17408 and #19088). */
5055
81.9k
    PyObject *copyreg_module = PyImport_GetModule(&_Py_ID(copyreg));
Line
Count
Source
374
81.9k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
81.9k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
81.9k
    _PyRuntime.global_objects.NAME
5056
81.9k
    if (copyreg_module != NULL) {
  Branch (5056:9): [True: 81.9k, False: 0]
5057
81.9k
        return copyreg_module;
5058
81.9k
    }
5059
0
    if (PyErr_Occurred()) {
  Branch (5059:9): [True: 0, False: 0]
5060
0
        return NULL;
5061
0
    }
5062
0
    return PyImport_Import(&_Py_ID(copyreg));
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
5063
0
}
5064
5065
static PyObject *
5066
_PyType_GetSlotNames(PyTypeObject *cls)
5067
76.4k
{
5068
76.4k
    PyObject *copyreg;
5069
76.4k
    PyObject *slotnames;
5070
5071
76.4k
    assert(PyType_Check(cls));
5072
5073
    /* Get the slot names from the cache in the class if possible. */
5074
76.4k
    slotnames = PyDict_GetItemWithError(cls->tp_dict, &_Py_ID(__slotnames__));
Line
Count
Source
374
76.4k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
76.4k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
76.4k
    _PyRuntime.global_objects.NAME
5075
76.4k
    if (slotnames != NULL) {
  Branch (5075:9): [True: 75.6k, False: 811]
5076
75.6k
        if (slotnames != Py_None && !PyList_Check(slotnames)) {
Line
Count
Source
654
151k
#define Py_None (&_Py_NoneStruct)
        if (slotnames != Py_None && !PyList_Check(slotnames)) {
Line
Count
Source
25
75.6k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
Line
Count
Source
782
75.6k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (5076:13): [True: 75.6k, False: 0]
  Branch (5076:37): [True: 0, False: 75.6k]
5077
0
            PyErr_Format(PyExc_TypeError,
5078
0
                         "%.200s.__slotnames__ should be a list or None, "
5079
0
                         "not %.200s",
5080
0
                         cls->tp_name, Py_TYPE(slotnames)->tp_name);
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5081
0
            return NULL;
5082
0
        }
5083
75.6k
        Py_INCREF(slotnames);
Line
Count
Source
512
75.6k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
75.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
75.6k
#  define _Py_CAST(type, expr) ((type)(expr))
5084
75.6k
        return slotnames;
5085
75.6k
    }
5086
811
    else {
5087
811
        if (PyErr_Occurred()) {
  Branch (5087:13): [True: 0, False: 811]
5088
0
            return NULL;
5089
0
        }
5090
        /* The class does not have the slot names cached yet. */
5091
811
    }
5092
5093
811
    copyreg = import_copyreg();
5094
811
    if (copyreg == NULL)
  Branch (5094:9): [True: 0, False: 811]
5095
0
        return NULL;
5096
5097
    /* Use _slotnames function from the copyreg module to find the slots
5098
       by this class and its bases. This function will cache the result
5099
       in __slotnames__. */
5100
811
    slotnames = PyObject_CallMethodOneArg(
5101
811
            copyreg, &_Py_ID(_slotnames), (PyObject *)cls);
Line
Count
Source
374
811
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
811
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
811
    _PyRuntime.global_objects.NAME
5102
811
    Py_DECREF(copyreg);
Line
Count
Source
548
811
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
811
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
811
#  define _Py_CAST(type, expr) ((type)(expr))
5103
811
    if (slotnames == NULL)
  Branch (5103:9): [True: 0, False: 811]
5104
0
        return NULL;
5105
5106
811
    if (slotnames != Py_None && !PyList_Check(slotnames)) {
Line
Count
Source
654
1.62k
#define Py_None (&_Py_NoneStruct)
    if (slotnames != Py_None && !PyList_Check(slotnames)) {
Line
Count
Source
25
811
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
Line
Count
Source
782
811
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (5106:9): [True: 811, False: 0]
  Branch (5106:33): [True: 0, False: 811]
5107
0
        PyErr_SetString(PyExc_TypeError,
5108
0
                        "copyreg._slotnames didn't return a list or None");
5109
0
        Py_DECREF(slotnames);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5110
0
        return NULL;
5111
0
    }
5112
5113
811
    return slotnames;
5114
811
}
5115
5116
static PyObject *
5117
object_getstate_default(PyObject *obj, int required)
5118
76.4k
{
5119
76.4k
    PyObject *state;
5120
76.4k
    PyObject *slotnames;
5121
5122
76.4k
    if (required && Py_TYPE(obj)->tp_itemsize) {
Line
Count
Source
138
71.6k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
71.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
71.6k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5122:9): [True: 71.6k, False: 4.84k]
  Branch (5122:21): [True: 9, False: 71.6k]
5123
9
        PyErr_Format(PyExc_TypeError,
5124
9
                     "cannot pickle %.200s objects",
5125
9
                     Py_TYPE(obj)->tp_name);
Line
Count
Source
138
9
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
5126
9
        return NULL;
5127
9
    }
5128
5129
76.4k
    if (_PyObject_IsInstanceDictEmpty(obj)) {
  Branch (5129:9): [True: 3.25k, False: 73.2k]
5130
3.25k
        state = Py_None;
Line
Count
Source
654
3.25k
#define Py_None (&_Py_NoneStruct)
5131
3.25k
        Py_INCREF(state);
Line
Count
Source
512
3.25k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
3.25k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.25k
#  define _Py_CAST(type, expr) ((type)(expr))
5132
3.25k
    }
5133
73.2k
    else {
5134
73.2k
        state = PyObject_GenericGetDict(obj, NULL);
5135
73.2k
        if (state == NULL) {
  Branch (5135:13): [True: 0, False: 73.2k]
5136
0
            return NULL;
5137
0
        }
5138
73.2k
    }
5139
5140
76.4k
    slotnames = _PyType_GetSlotNames(Py_TYPE(obj));
Line
Count
Source
138
76.4k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
76.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
76.4k
#  define _Py_CAST(type, expr) ((type)(expr))
5141
76.4k
    if (slotnames == NULL) {
  Branch (5141:9): [True: 0, False: 76.4k]
5142
0
        Py_DECREF(state);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5143
0
        return NULL;
5144
0
    }
5145
5146
76.4k
    assert(slotnames == Py_None || PyList_Check(slotnames));
5147
76.4k
    if (required) {
  Branch (5147:9): [True: 71.6k, False: 4.84k]
5148
71.6k
        Py_ssize_t basicsize = PyBaseObject_Type.tp_basicsize;
5149
71.6k
        if (Py_TYPE(obj)->tp_dictoffset &&
Line
Count
Source
138
71.6k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
71.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
71.6k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5149:13): [True: 70.5k, False: 1.06k]
5150
71.6k
            (Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0)
Line
Count
Source
138
70.5k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
70.5k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
70.5k
#  define _Py_CAST(type, expr) ((type)(expr))
            (Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0)
Line
Count
Source
359
70.5k
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
  Branch (5150:13): [True: 36, False: 70.5k]
5151
36
        {
5152
36
            basicsize += sizeof(PyObject *);
5153
36
        }
5154
71.6k
        if (Py_TYPE(obj)->tp_weaklistoffset) {
Line
Count
Source
138
71.6k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
71.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
71.6k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5154:13): [True: 70.5k, False: 1.05k]
5155
70.5k
            basicsize += sizeof(PyObject *);
5156
70.5k
        }
5157
71.6k
        if (slotnames != Py_None) {
Line
Count
Source
654
71.6k
#define Py_None (&_Py_NoneStruct)
  Branch (5157:13): [True: 71.6k, False: 0]
5158
71.6k
            basicsize += sizeof(PyObject *) * PyList_GET_SIZE(slotnames);
Line
Count
Source
37
71.6k
#define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
71.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
71.6k
#  define _Py_CAST(type, expr) ((type)(expr))
5159
71.6k
        }
5160
71.6k
        if (Py_TYPE(obj)->tp_basicsize > basicsize) {
Line
Count
Source
138
71.6k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
71.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
71.6k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5160:13): [True: 281, False: 71.3k]
5161
281
            Py_DECREF(slotnames);
Line
Count
Source
548
281
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
281
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
281
#  define _Py_CAST(type, expr) ((type)(expr))
5162
281
            Py_DECREF(state);
Line
Count
Source
548
281
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
281
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
281
#  define _Py_CAST(type, expr) ((type)(expr))
5163
281
            PyErr_Format(PyExc_TypeError,
5164
281
                         "cannot pickle '%.200s' object",
5165
281
                         Py_TYPE(obj)->tp_name);
Line
Count
Source
138
281
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
281
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
281
#  define _Py_CAST(type, expr) ((type)(expr))
5166
281
            return NULL;
5167
281
        }
5168
71.6k
    }
5169
5170
76.2k
    if (slotnames != Py_None && PyList_GET_SIZE(slotnames) > 0) {
Line
Count
Source
654
152k
#define Py_None (&_Py_NoneStruct)
    if (slotnames != Py_None && PyList_GET_SIZE(slotnames) > 0) {
Line
Count
Source
37
76.2k
#define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
76.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
76.2k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5170:9): [True: 76.2k, False: 0]
  Branch (5170:33): [True: 965, False: 75.2k]
5171
965
        PyObject *slots;
5172
965
        Py_ssize_t slotnames_size, i;
5173
5174
965
        slots = PyDict_New();
5175
965
        if (slots == NULL) {
  Branch (5175:13): [True: 0, False: 965]
5176
0
            Py_DECREF(slotnames);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5177
0
            Py_DECREF(state);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5178
0
            return NULL;
5179
0
        }
5180
5181
965
        slotnames_size = PyList_GET_SIZE(slotnames);
Line
Count
Source
37
965
#define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
965
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
965
#  define _Py_CAST(type, expr) ((type)(expr))
5182
16.6k
        for (i = 0; i < slotnames_size; i++) {
  Branch (5182:21): [True: 15.7k, False: 965]
5183
15.7k
            PyObject *name, *value;
5184
5185
15.7k
            name = PyList_GET_ITEM(slotnames, i);
Line
Count
Source
39
15.7k
#define PyList_GET_ITEM(op, index) (_PyList_CAST(op)->ob_item[(index)])
Line
Count
Source
29
15.7k
    (assert(PyList_Check(op)), _Py_CAST(PyListObject*, (op)))
Line
Count
Source
71
15.7k
#  define _Py_CAST(type, expr) ((type)(expr))
5186
15.7k
            Py_INCREF(name);
Line
Count
Source
512
15.7k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
15.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
15.7k
#  define _Py_CAST(type, expr) ((type)(expr))
5187
15.7k
            if (_PyObject_LookupAttr(obj, name, &value) < 0) {
  Branch (5187:17): [True: 0, False: 15.7k]
5188
0
                Py_DECREF(name);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5189
0
                goto error;
5190
0
            }
5191
15.7k
            if (value == NULL) {
  Branch (5191:17): [True: 1.84k, False: 13.8k]
5192
1.84k
                Py_DECREF(name);
Line
Count
Source
548
1.84k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1.84k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.84k
#  define _Py_CAST(type, expr) ((type)(expr))
5193
                /* It is not an error if the attribute is not present. */
5194
1.84k
            }
5195
13.8k
            else {
5196
13.8k
                int err = PyDict_SetItem(slots, name, value);
5197
13.8k
                Py_DECREF(name);
Line
Count
Source
548
13.8k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
13.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.8k
#  define _Py_CAST(type, expr) ((type)(expr))
5198
13.8k
                Py_DECREF(value);
Line
Count
Source
548
13.8k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
13.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13.8k
#  define _Py_CAST(type, expr) ((type)(expr))
5199
13.8k
                if (err) {
  Branch (5199:21): [True: 0, False: 13.8k]
5200
0
                    goto error;
5201
0
                }
5202
13.8k
            }
5203
5204
            /* The list is stored on the class so it may mutate while we
5205
               iterate over it */
5206
15.7k
            if (slotnames_size != PyList_GET_SIZE(slotnames)) {
Line
Count
Source
37
15.7k
#define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
15.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
15.7k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5206:17): [True: 0, False: 15.7k]
5207
0
                PyErr_Format(PyExc_RuntimeError,
5208
0
                             "__slotsname__ changed size during iteration");
5209
0
                goto error;
5210
0
            }
5211
5212
            /* We handle errors within the loop here. */
5213
15.7k
            if (0) {
  Branch (5213:17): [Folded - Ignored]
5214
0
              error:
5215
0
                Py_DECREF(slotnames);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5216
0
                Py_DECREF(slots);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5217
0
                Py_DECREF(state);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5218
0
                return NULL;
5219
0
            }
5220
15.7k
        }
5221
5222
        /* If we found some slot attributes, pack them in a tuple along
5223
           the original attribute dictionary. */
5224
965
        if (PyDict_GET_SIZE(slots) > 0) {
Line
Count
Source
55
965
#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
965
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
965
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5224:13): [True: 958, False: 7]
5225
958
            PyObject *state2;
5226
5227
958
            state2 = PyTuple_Pack(2, state, slots);
5228
958
            Py_DECREF(state);
Line
Count
Source
548
958
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
958
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
958
#  define _Py_CAST(type, expr) ((type)(expr))
5229
958
            if (state2 == NULL) {
  Branch (5229:17): [True: 0, False: 958]
5230
0
                Py_DECREF(slotnames);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5231
0
                Py_DECREF(slots);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5232
0
                return NULL;
5233
0
            }
5234
958
            state = state2;
5235
958
        }
5236
965
        Py_DECREF(slots);
Line
Count
Source
548
965
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
965
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
965
#  define _Py_CAST(type, expr) ((type)(expr))
5237
965
    }
5238
76.2k
    Py_DECREF(slotnames);
Line
Count
Source
548
76.2k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
76.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
76.2k
#  define _Py_CAST(type, expr) ((type)(expr))
5239
5240
76.2k
    return state;
5241
76.2k
}
5242
5243
static PyObject *
5244
object_getstate(PyObject *obj, int required)
5245
80.1k
{
5246
80.1k
    PyObject *getstate, *state;
5247
5248
80.1k
    getstate = PyObject_GetAttr(obj, &_Py_ID(__getstate__));
Line
Count
Source
374
80.1k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
80.1k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
80.1k
    _PyRuntime.global_objects.NAME
5249
80.1k
    if (getstate == NULL) {
  Branch (5249:9): [True: 0, False: 80.1k]
5250
0
        return NULL;
5251
0
    }
5252
80.1k
    if (PyCFunction_Check(getstate) &&
Line
Count
Source
17
80.1k
#define PyCFunction_Check(op) PyObject_TypeCheck((op), &PyCFunction_Type)
Line
Count
Source
271
160k
#  define PyObject_TypeCheck(ob, type) PyObject_TypeCheck(_PyObject_CAST(ob), (type))
Line
Count
Source
109
80.1k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
80.1k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (271:40): [True: 74.8k, False: 5.28k]
5253
80.1k
        PyCFunction_GET_SELF(getstate) == obj &&
Line
Count
Source
52
74.8k
#define PyCFunction_GET_SELF(func) PyCFunction_GET_SELF(_PyObject_CAST(func))
Line
Count
Source
109
74.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
74.8k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5253:9): [True: 74.8k, False: 0]
5254
80.1k
        PyCFunction_GET_FUNCTION(getstate) == object___getstate__)
Line
Count
Source
43
74.8k
#define PyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(_PyObject_CAST(func))
Line
Count
Source
109
74.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
74.8k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5254:9): [True: 74.7k, False: 106]
5255
74.7k
    {
5256
        /* If __getstate__ is not overriden pass the required argument. */
5257
74.7k
        state = object_getstate_default(obj, required);
5258
74.7k
    }
5259
5.39k
    else {
5260
5.39k
        state = _PyObject_CallNoArgs(getstate);
5261
5.39k
    }
5262
80.1k
    Py_DECREF(getstate);
Line
Count
Source
548
80.1k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
80.1k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
80.1k
#  define _Py_CAST(type, expr) ((type)(expr))
5263
80.1k
    return state;
5264
80.1k
}
5265
5266
PyObject *
5267
_PyObject_GetState(PyObject *obj)
5268
719
{
5269
719
    return object_getstate(obj, 0);
5270
719
}
5271
5272
/*[clinic input]
5273
object.__getstate__
5274
5275
Helper for pickle.
5276
[clinic start generated code]*/
5277
5278
static PyObject *
5279
object___getstate___impl(PyObject *self)
5280
/*[clinic end generated code: output=5a2500dcb6217e9e input=692314d8fbe194ee]*/
5281
1.73k
{
5282
1.73k
    return object_getstate_default(self, 0);
5283
1.73k
}
5284
5285
static int
5286
_PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs)
5287
79.4k
{
5288
79.4k
    PyObject *getnewargs, *getnewargs_ex;
5289
5290
79.4k
    if (args == NULL || kwargs == NULL) {
  Branch (5290:9): [True: 0, False: 79.4k]
  Branch (5290:25): [True: 0, False: 79.4k]
5291
0
        PyErr_BadInternalCall();
Line
Count
Source
222
0
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
5292
0
        return -1;
5293
0
    }
5294
5295
    /* We first attempt to fetch the arguments for __new__ by calling
5296
       __getnewargs_ex__ on the object. */
5297
79.4k
    getnewargs_ex = _PyObject_LookupSpecial(obj, &_Py_ID(__getnewargs_ex__));
Line
Count
Source
374
79.4k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
79.4k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
79.4k
    _PyRuntime.global_objects.NAME
5298
79.4k
    if (getnewargs_ex != NULL) {
  Branch (5298:9): [True: 92, False: 79.3k]
5299
92
        PyObject *newargs = _PyObject_CallNoArgs(getnewargs_ex);
5300
92
        Py_DECREF(getnewargs_ex);
Line
Count
Source
548
92
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
92
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
92
#  define _Py_CAST(type, expr) ((type)(expr))
5301
92
        if (newargs == NULL) {
  Branch (5301:13): [True: 4, False: 88]
5302
4
            return -1;
5303
4
        }
5304
88
        if (!PyTuple_Check(newargs)) {
Line
Count
Source
27
88
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
Line
Count
Source
782
88
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (5304:13): [True: 4, False: 84]
5305
4
            PyErr_Format(PyExc_TypeError,
5306
4
                         "__getnewargs_ex__ should return a tuple, "
5307
4
                         "not '%.200s'", Py_TYPE(newargs)->tp_name);
Line
Count
Source
138
4
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
5308
4
            Py_DECREF(newargs);
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
5309
4
            return -1;
5310
4
        }
5311
84
        if (PyTuple_GET_SIZE(newargs) != 2) {
Line
Count
Source
26
84
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
84
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
84
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5311:13): [True: 4, False: 80]
5312
4
            PyErr_Format(PyExc_ValueError,
5313
4
                         "__getnewargs_ex__ should return a tuple of "
5314
4
                         "length 2, not %zd", PyTuple_GET_SIZE(newargs));
Line
Count
Source
26
4
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
5315
4
            Py_DECREF(newargs);
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
5316
4
            return -1;
5317
4
        }
5318
80
        *args = PyTuple_GET_ITEM(newargs, 0);
Line
Count
Source
28
80
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
80
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
80
#  define _Py_CAST(type, expr) ((type)(expr))
5319
80
        Py_INCREF(*args);
Line
Count
Source
512
80
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
80
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
80
#  define _Py_CAST(type, expr) ((type)(expr))
5320
80
        *kwargs = PyTuple_GET_ITEM(newargs, 1);
Line
Count
Source
28
80
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
80
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
80
#  define _Py_CAST(type, expr) ((type)(expr))
5321
80
        Py_INCREF(*kwargs);
Line
Count
Source
512
80
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
80
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
80
#  define _Py_CAST(type, expr) ((type)(expr))
5322
80
        Py_DECREF(newargs);
Line
Count
Source
548
80
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
80
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
80
#  define _Py_CAST(type, expr) ((type)(expr))
5323
5324
        /* XXX We should perhaps allow None to be passed here. */
5325
80
        if (!PyTuple_Check(*args)) {
Line
Count
Source
27
80
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
Line
Count
Source
782
80
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (5325:13): [True: 4, False: 76]
5326
4
            PyErr_Format(PyExc_TypeError,
5327
4
                         "first item of the tuple returned by "
5328
4
                         "__getnewargs_ex__ must be a tuple, not '%.200s'",
5329
4
                         Py_TYPE(*args)->tp_name);
Line
Count
Source
138
4
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
5330
4
            Py_CLEAR(*args);
Line
Count
Source
587
4
    do {                                        \
588
4
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
589
4
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 4, False: 0]
590
4
            (op) = NULL;                        \
591
4
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
592
4
        }                                       \
593
4
    } while (0)
  Branch (593:14): [Folded - Ignored]
5331
4
            Py_CLEAR(*kwargs);
Line
Count
Source
587
4
    do {                                        \
588
4
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
589
4
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 4, False: 0]
590
4
            (op) = NULL;                        \
591
4
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
592
4
        }                                       \
593
4
    } while (0)
  Branch (593:14): [Folded - Ignored]
5332
4
            return -1;
5333
4
        }
5334
76
        if (!PyDict_Check(*kwargs)) {
Line
Count
Source
18
76
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
Line
Count
Source
782
76
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (5334:13): [True: 4, False: 72]
5335
4
            PyErr_Format(PyExc_TypeError,
5336
4
                         "second item of the tuple returned by "
5337
4
                         "__getnewargs_ex__ must be a dict, not '%.200s'",
5338
4
                         Py_TYPE(*kwargs)->tp_name);
Line
Count
Source
138
4
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
5339
4
            Py_CLEAR(*args);
Line
Count
Source
587
4
    do {                                        \
588
4
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
589
4
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 4, False: 0]
590
4
            (op) = NULL;                        \
591
4
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
592
4
        }                                       \
593
4
    } while (0)
  Branch (593:14): [Folded - Ignored]
5340
4
            Py_CLEAR(*kwargs);
Line
Count
Source
587
4
    do {                                        \
588
4
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
589
4
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 4, False: 0]
590
4
            (op) = NULL;                        \
591
4
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
592
4
        }                                       \
593
4
    } while (0)
  Branch (593:14): [Folded - Ignored]
5341
4
            return -1;
5342
4
        }
5343
72
        return 0;
5344
79.3k
    } else if (PyErr_Occurred()) {
  Branch (5344:16): [True: 0, False: 79.3k]
5345
0
        return -1;
5346
0
    }
5347
5348
    /* The object does not have __getnewargs_ex__ so we fallback on using
5349
       __getnewargs__ instead. */
5350
79.3k
    getnewargs = _PyObject_LookupSpecial(obj, &_Py_ID(__getnewargs__));
Line
Count
Source
374
79.3k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
79.3k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
79.3k
    _PyRuntime.global_objects.NAME
5351
79.3k
    if (getnewargs != NULL) {
  Branch (5351:9): [True: 1.22k, False: 78.1k]
5352
1.22k
        *args = _PyObject_CallNoArgs(getnewargs);
5353
1.22k
        Py_DECREF(getnewargs);
Line
Count
Source
548
1.22k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1.22k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.22k
#  define _Py_CAST(type, expr) ((type)(expr))
5354
1.22k
        if (*args == NULL) {
  Branch (5354:13): [True: 0, False: 1.22k]
5355
0
            return -1;
5356
0
        }
5357
1.22k
        if (!PyTuple_Check(*args)) {
Line
Count
Source
27
1.22k
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
Line
Count
Source
782
1.22k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (5357:13): [True: 4, False: 1.21k]
5358
4
            PyErr_Format(PyExc_TypeError,
5359
4
                         "__getnewargs__ should return a tuple, "
5360
4
                         "not '%.200s'", Py_TYPE(*args)->tp_name);
Line
Count
Source
138
4
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
5361
4
            Py_CLEAR(*args);
Line
Count
Source
587
4
    do {                                        \
588
4
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
589
4
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 4, False: 0]
590
4
            (op) = NULL;                        \
591
4
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
592
4
        }                                       \
593
4
    } while (0)
  Branch (593:14): [Folded - Ignored]
5362
4
            return -1;
5363
4
        }
5364
1.21k
        *kwargs = NULL;
5365
1.21k
        return 0;
5366
78.1k
    } else if (PyErr_Occurred()) {
  Branch (5366:16): [True: 0, False: 78.1k]
5367
0
        return -1;
5368
0
    }
5369
5370
    /* The object does not have __getnewargs_ex__ and __getnewargs__. This may
5371
       mean __new__ does not takes any arguments on this object, or that the
5372
       object does not implement the reduce protocol for pickling or
5373
       copying. */
5374
78.1k
    *args = NULL;
5375
78.1k
    *kwargs = NULL;
5376
78.1k
    return 0;
5377
79.3k
}
5378
5379
static int
5380
_PyObject_GetItemsIter(PyObject *obj, PyObject **listitems,
5381
                       PyObject **dictitems)
5382
79.0k
{
5383
79.0k
    if (listitems == NULL || dictitems == NULL) {
  Branch (5383:9): [True: 0, False: 79.0k]
  Branch (5383:30): [True: 0, False: 79.0k]
5384
0
        PyErr_BadInternalCall();
Line
Count
Source
222
0
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
5385
0
        return -1;
5386
0
    }
5387
5388
79.0k
    if (!PyList_Check(obj)) {
Line
Count
Source
25
79.0k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
Line
Count
Source
782
79.0k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (5388:9): [True: 78.1k, False: 906]
5389
78.1k
        *listitems = Py_None;
Line
Count
Source
654
78.1k
#define Py_None (&_Py_NoneStruct)
5390
78.1k
        Py_INCREF(*listitems);
Line
Count
Source
512
78.1k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
78.1k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
78.1k
#  define _Py_CAST(type, expr) ((type)(expr))
5391
78.1k
    }
5392
906
    else {
5393
906
        *listitems = PyObject_GetIter(obj);
5394
906
        if (*listitems == NULL)
  Branch (5394:13): [True: 0, False: 906]
5395
0
            return -1;
5396
906
    }
5397
5398
79.0k
    if (!PyDict_Check(obj)) {
Line
Count
Source
18
79.0k
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
Line
Count
Source
782
79.0k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (5398:9): [True: 78.7k, False: 280]
5399
78.7k
        *dictitems = Py_None;
Line
Count
Source
654
78.7k
#define Py_None (&_Py_NoneStruct)
5400
78.7k
        Py_INCREF(*dictitems);
Line
Count
Source
512
78.7k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
78.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
78.7k
#  define _Py_CAST(type, expr) ((type)(expr))
5401
78.7k
    }
5402
280
    else {
5403
280
        PyObject *items = PyObject_CallMethodNoArgs(obj, &_Py_ID(items));
Line
Count
Source
374
280
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
280
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
280
    _PyRuntime.global_objects.NAME
5404
280
        if (items == NULL) {
  Branch (5404:13): [True: 0, False: 280]
5405
0
            Py_CLEAR(*listitems);
Line
Count
Source
587
0
    do {                                        \
588
0
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
589
0
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 0, False: 0]
590
0
            (op) = NULL;                        \
591
0
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
592
0
        }                                       \
593
0
    } while (0)
  Branch (593:14): [Folded - Ignored]
5406
0
            return -1;
5407
0
        }
5408
280
        *dictitems = PyObject_GetIter(items);
5409
280
        Py_DECREF(items);
Line
Count
Source
548
280
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
280
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
280
#  define _Py_CAST(type, expr) ((type)(expr))
5410
280
        if (*dictitems == NULL) {
  Branch (5410:13): [True: 0, False: 280]
5411
0
            Py_CLEAR(*listitems);
Line
Count
Source
587
0
    do {                                        \
588
0
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
589
0
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 0, False: 0]
590
0
            (op) = NULL;                        \
591
0
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
592
0
        }                                       \
593
0
    } while (0)
  Branch (593:14): [Folded - Ignored]
5412
0
            return -1;
5413
0
        }
5414
280
    }
5415
5416
79.0k
    assert(*listitems != NULL && *dictitems != NULL);
5417
5418
79.0k
    return 0;
5419
79.0k
}
5420
5421
static PyObject *
5422
reduce_newobj(PyObject *obj)
5423
79.5k
{
5424
79.5k
    PyObject *args = NULL, *kwargs = NULL;
5425
79.5k
    PyObject *copyreg;
5426
79.5k
    PyObject *newobj, *newargs, *state, *listitems, *dictitems;
5427
79.5k
    PyObject *result;
5428
79.5k
    int hasargs;
5429
5430
79.5k
    if (Py_TYPE(obj)->tp_new == NULL) {
Line
Count
Source
138
79.5k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
79.5k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.5k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5430:9): [True: 49, False: 79.4k]
5431
49
        PyErr_Format(PyExc_TypeError,
5432
49
                     "cannot pickle '%.200s' object",
5433
49
                     Py_TYPE(obj)->tp_name);
Line
Count
Source
138
49
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
49
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
49
#  define _Py_CAST(type, expr) ((type)(expr))
5434
49
        return NULL;
5435
49
    }
5436
79.4k
    if (_PyObject_GetNewArguments(obj, &args, &kwargs) < 0)
  Branch (5436:9): [True: 24, False: 79.4k]
5437
24
        return NULL;
5438
5439
79.4k
    copyreg = import_copyreg();
5440
79.4k
    if (copyreg == NULL) {
  Branch (5440:9): [True: 0, False: 79.4k]
5441
0
        Py_XDECREF(args);
Line
Count
Source
613
0
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5442
0
        Py_XDECREF(kwargs);
Line
Count
Source
613
0
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5443
0
        return NULL;
5444
0
    }
5445
79.4k
    hasargs = (args != NULL);
5446
79.4k
    if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) {
Line
Count
Source
55
72
#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
72
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
72
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5446:9): [True: 79.3k, False: 72]
  Branch (5446:27): [True: 8, False: 64]
5447
79.3k
        PyObject *cls;
5448
79.3k
        Py_ssize_t i, n;
5449
5450
79.3k
        Py_XDECREF(kwargs);
Line
Count
Source
613
79.3k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
79.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.3k
#  define _Py_CAST(type, expr) ((type)(expr))
5451
79.3k
        newobj = PyObject_GetAttr(copyreg, &_Py_ID(__newobj__));
Line
Count
Source
374
79.3k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
79.3k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
79.3k
    _PyRuntime.global_objects.NAME
5452
79.3k
        Py_DECREF(copyreg);
Line
Count
Source
548
79.3k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
79.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.3k
#  define _Py_CAST(type, expr) ((type)(expr))
5453
79.3k
        if (newobj == NULL) {
  Branch (5453:13): [True: 0, False: 79.3k]
5454
0
            Py_XDECREF(args);
Line
Count
Source
613
0
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5455
0
            return NULL;
5456
0
        }
5457
79.3k
        n = args ? PyTuple_GET_SIZE(args) : 0;
Line
Count
Source
26
1.22k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
1.22k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.22k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5457:13): [True: 1.22k, False: 78.1k]
5458
79.3k
        newargs = PyTuple_New(n+1);
5459
79.3k
        if (newargs == NULL) {
  Branch (5459:13): [True: 0, False: 79.3k]
5460
0
            Py_XDECREF(args);
Line
Count
Source
613
0
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5461
0
            Py_DECREF(newobj);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5462
0
            return NULL;
5463
0
        }
5464
79.3k
        cls = (PyObject *) Py_TYPE(obj);
Line
Count
Source
138
79.3k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
79.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.3k
#  define _Py_CAST(type, expr) ((type)(expr))
5465
79.3k
        Py_INCREF(cls);
Line
Count
Source
512
79.3k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
79.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.3k
#  define _Py_CAST(type, expr) ((type)(expr))
5466
79.3k
        PyTuple_SET_ITEM(newargs, 0, cls);
Line
Count
Source
37
79.3k
    PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
79.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.3k
#  define _Py_CAST(type, expr) ((type)(expr))
    PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
79.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.3k
#  define _Py_CAST(type, expr) ((type)(expr))
5467
81.9k
        for (i = 0; i < n; i++) {
  Branch (5467:21): [True: 2.57k, False: 79.3k]
5468
2.57k
            PyObject *v = PyTuple_GET_ITEM(args, i);
Line
Count
Source
28
2.57k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
2.57k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
2.57k
#  define _Py_CAST(type, expr) ((type)(expr))
5469
2.57k
            Py_INCREF(v);
Line
Count
Source
512
2.57k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
2.57k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.57k
#  define _Py_CAST(type, expr) ((type)(expr))
5470
2.57k
            PyTuple_SET_ITEM(newargs, i+1, v);
Line
Count
Source
37
2.57k
    PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
2.57k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.57k
#  define _Py_CAST(type, expr) ((type)(expr))
    PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
Line
Count
Source
109
2.57k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.57k
#  define _Py_CAST(type, expr) ((type)(expr))
5471
2.57k
        }
5472
79.3k
        Py_XDECREF(args);
Line
Count
Source
613
79.3k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
79.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.3k
#  define _Py_CAST(type, expr) ((type)(expr))
5473
79.3k
    }
5474
64
    else if (args != NULL) {
  Branch (5474:14): [True: 64, False: 0]
5475
64
        newobj = PyObject_GetAttr(copyreg, &_Py_ID(__newobj_ex__));
Line
Count
Source
374
64
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
64
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
64
    _PyRuntime.global_objects.NAME
5476
64
        Py_DECREF(copyreg);
Line
Count
Source
548
64
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
64
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
64
#  define _Py_CAST(type, expr) ((type)(expr))
5477
64
        if (newobj == NULL) {
  Branch (5477:13): [True: 0, False: 64]
5478
0
            Py_DECREF(args);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5479
0
            Py_DECREF(kwargs);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5480
0
            return NULL;
5481
0
        }
5482
64
        newargs = PyTuple_Pack(3, Py_TYPE(obj), args, kwargs);
Line
Count
Source
138
64
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
64
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
64
#  define _Py_CAST(type, expr) ((type)(expr))
5483
64
        Py_DECREF(args);
Line
Count
Source
548
64
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
64
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
64
#  define _Py_CAST(type, expr) ((type)(expr))
5484
64
        Py_DECREF(kwargs);
Line
Count
Source
548
64
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
64
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
64
#  define _Py_CAST(type, expr) ((type)(expr))
5485
64
        if (newargs == NULL) {
  Branch (5485:13): [True: 0, False: 64]
5486
0
            Py_DECREF(newobj);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5487
0
            return NULL;
5488
0
        }
5489
64
    }
5490
0
    else {
5491
        /* args == NULL */
5492
0
        Py_DECREF(kwargs);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5493
0
        PyErr_BadInternalCall();
Line
Count
Source
222
0
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
5494
0
        return NULL;
5495
0
    }
5496
5497
79.4k
    state = object_getstate(obj, !(hasargs || PyList_Check(obj) || PyDict_Check(obj)));
Line
Count
Source
25
78.1k
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
Line
Count
Source
782
157k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 872, False: 77.2k]
    state = object_getstate(obj, !(hasargs || PyList_Check(obj) || PyDict_Check(obj)));
Line
Count
Source
18
77.2k
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
Line
Count
Source
782
77.2k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 280, False: 76.9k]
  Branch (5497:36): [True: 1.29k, False: 78.1k]
5498
79.4k
    if (state == NULL) {
  Branch (5498:9): [True: 367, False: 79.0k]
5499
367
        Py_DECREF(newobj);
Line
Count
Source
548
367
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
367
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
367
#  define _Py_CAST(type, expr) ((type)(expr))
5500
367
        Py_DECREF(newargs);
Line
Count
Source
548
367
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
367
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
367
#  define _Py_CAST(type, expr) ((type)(expr))
5501
367
        return NULL;
5502
367
    }
5503
79.0k
    if (_PyObject_GetItemsIter(obj, &listitems, &dictitems) < 0) {
  Branch (5503:9): [True: 0, False: 79.0k]
5504
0
        Py_DECREF(newobj);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5505
0
        Py_DECREF(newargs);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5506
0
        Py_DECREF(state);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5507
0
        return NULL;
5508
0
    }
5509
5510
79.0k
    result = PyTuple_Pack(5, newobj, newargs, state, listitems, dictitems);
5511
79.0k
    Py_DECREF(newobj);
Line
Count
Source
548
79.0k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
79.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.0k
#  define _Py_CAST(type, expr) ((type)(expr))
5512
79.0k
    Py_DECREF(newargs);
Line
Count
Source
548
79.0k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
79.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.0k
#  define _Py_CAST(type, expr) ((type)(expr))
5513
79.0k
    Py_DECREF(state);
Line
Count
Source
548
79.0k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
79.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.0k
#  define _Py_CAST(type, expr) ((type)(expr))
5514
79.0k
    Py_DECREF(listitems);
Line
Count
Source
548
79.0k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
79.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.0k
#  define _Py_CAST(type, expr) ((type)(expr))
5515
79.0k
    Py_DECREF(dictitems);
Line
Count
Source
548
79.0k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
79.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
79.0k
#  define _Py_CAST(type, expr) ((type)(expr))
5516
79.0k
    return result;
5517
79.0k
}
5518
5519
/*
5520
 * There were two problems when object.__reduce__ and object.__reduce_ex__
5521
 * were implemented in the same function:
5522
 *  - trying to pickle an object with a custom __reduce__ method that
5523
 *    fell back to object.__reduce__ in certain circumstances led to
5524
 *    infinite recursion at Python level and eventual RecursionError.
5525
 *  - Pickling objects that lied about their type by overwriting the
5526
 *    __class__ descriptor could lead to infinite recursion at C level
5527
 *    and eventual segfault.
5528
 *
5529
 * Because of backwards compatibility, the two methods still have to
5530
 * behave in the same way, even if this is not required by the pickle
5531
 * protocol. This common functionality was moved to the _common_reduce
5532
 * function.
5533
 */
5534
static PyObject *
5535
_common_reduce(PyObject *self, int proto)
5536
81.1k
{
5537
81.1k
    PyObject *copyreg, *res;
5538
5539
81.1k
    if (proto >= 2)
  Branch (5539:9): [True: 79.5k, False: 1.65k]
5540
79.5k
        return reduce_newobj(self);
5541
5542
1.65k
    copyreg = import_copyreg();
5543
1.65k
    if (!copyreg)
  Branch (5543:9): [True: 0, False: 1.65k]
5544
0
        return NULL;
5545
5546
1.65k
    res = PyObject_CallMethod(copyreg, "_reduce_ex", "Oi", self, proto);
5547
1.65k
    Py_DECREF(copyreg);
Line
Count
Source
548
1.65k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1.65k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.65k
#  define _Py_CAST(type, expr) ((type)(expr))
5548
5549
1.65k
    return res;
5550
1.65k
}
5551
5552
/*[clinic input]
5553
object.__reduce__
5554
5555
Helper for pickle.
5556
[clinic start generated code]*/
5557
5558
static PyObject *
5559
object___reduce___impl(PyObject *self)
5560
/*[clinic end generated code: output=d4ca691f891c6e2f input=11562e663947e18b]*/
5561
57
{
5562
57
    return _common_reduce(self, 0);
5563
57
}
5564
5565
/*[clinic input]
5566
object.__reduce_ex__
5567
5568
  protocol: int
5569
  /
5570
5571
Helper for pickle.
5572
[clinic start generated code]*/
5573
5574
static PyObject *
5575
object___reduce_ex___impl(PyObject *self, int protocol)
5576
/*[clinic end generated code: output=2e157766f6b50094 input=f326b43fb8a4c5ff]*/
5577
167k
{
5578
167k
    static PyObject *objreduce;
5579
167k
    PyObject *reduce, *res;
5580
5581
167k
    if (objreduce == NULL) {
  Branch (5581:9): [True: 1, False: 167k]
5582
1
        objreduce = PyDict_GetItemWithError(
5583
1
                PyBaseObject_Type.tp_dict, &_Py_ID(__reduce__));
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
5584
1
        if (objreduce == NULL && PyErr_Occurred()) {
  Branch (5584:13): [True: 0, False: 1]
  Branch (5584:34): [True: 0, False: 0]
5585
0
            return NULL;
5586
0
        }
5587
1
    }
5588
5589
167k
    if (_PyObject_LookupAttr(self, &_Py_ID(__reduce__), &reduce) < 0) {
Line
Count
Source
374
167k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
167k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
167k
    _PyRuntime.global_objects.NAME
  Branch (5589:9): [True: 0, False: 167k]
5590
0
        return NULL;
5591
0
    }
5592
167k
    if (reduce != NULL) {
  Branch (5592:9): [True: 167k, False: 0]
5593
167k
        PyObject *cls, *clsreduce;
5594
167k
        int override;
5595
5596
167k
        cls = (PyObject *) Py_TYPE(self);
Line
Count
Source
138
167k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
167k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
167k
#  define _Py_CAST(type, expr) ((type)(expr))
5597
167k
        clsreduce = PyObject_GetAttr(cls, &_Py_ID(__reduce__));
Line
Count
Source
374
167k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
167k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
167k
    _PyRuntime.global_objects.NAME
5598
167k
        if (clsreduce == NULL) {
  Branch (5598:13): [True: 0, False: 167k]
5599
0
            Py_DECREF(reduce);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5600
0
            return NULL;
5601
0
        }
5602
167k
        override = (clsreduce != objreduce);
5603
167k
        Py_DECREF(clsreduce);
Line
Count
Source
548
167k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
167k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
167k
#  define _Py_CAST(type, expr) ((type)(expr))
5604
167k
        if (override) {
  Branch (5604:13): [True: 85.9k, False: 81.1k]
5605
85.9k
            res = _PyObject_CallNoArgs(reduce);
5606
85.9k
            Py_DECREF(reduce);
Line
Count
Source
548
85.9k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
85.9k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
85.9k
#  define _Py_CAST(type, expr) ((type)(expr))
5607
85.9k
            return res;
5608
85.9k
        }
5609
81.1k
        else
5610
81.1k
            Py_DECREF(reduce);
Line
Count
Source
548
81.1k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
81.1k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
81.1k
#  define _Py_CAST(type, expr) ((type)(expr))
5611
167k
    }
5612
5613
81.1k
    return _common_reduce(self, protocol);
5614
167k
}
5615
5616
static PyObject *
5617
object_subclasshook(PyObject *cls, PyObject *args)
5618
4.10k
{
5619
4.10k
    Py_RETURN_NOTIMPLEMENTED;
Line
Count
Source
671
4.10k
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4.10k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4.10k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4.10k
#  define _Py_CAST(type, expr) ((type)(expr))
5620
4.10k
}
5621
5622
PyDoc_STRVAR(object_subclasshook_doc,
5623
"Abstract classes can override this to customize issubclass().\n"
5624
"\n"
5625
"This is invoked early on by abc.ABCMeta.__subclasscheck__().\n"
5626
"It should return True, False or NotImplemented.  If it returns\n"
5627
"NotImplemented, the normal algorithm is used.  Otherwise, it\n"
5628
"overrides the normal algorithm (and the outcome is cached).\n");
5629
5630
static PyObject *
5631
object_init_subclass(PyObject *cls, PyObject *arg)
5632
86.5k
{
5633
86.5k
    Py_RETURN_NONE;
Line
Count
Source
661
86.5k
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
86.5k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
86.5k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.5k
#  define _Py_CAST(type, expr) ((type)(expr))
5634
86.5k
}
5635
5636
PyDoc_STRVAR(object_init_subclass_doc,
5637
"This method is called when a class is subclassed.\n"
5638
"\n"
5639
"The default implementation does nothing. It may be\n"
5640
"overridden to extend subclasses.\n");
5641
5642
/*[clinic input]
5643
object.__format__
5644
5645
  format_spec: unicode
5646
  /
5647
5648
Default object formatter.
5649
[clinic start generated code]*/
5650
5651
static PyObject *
5652
object___format___impl(PyObject *self, PyObject *format_spec)
5653
/*[clinic end generated code: output=34897efb543a974b input=7c3b3bc53a6fb7fa]*/
5654
6.65k
{
5655
    /* Issue 7994: If we're converting to a string, we
5656
       should reject format specifications */
5657
6.65k
    if (PyUnicode_GET_LENGTH(format_spec) > 0) {
Line
Count
Source
275
6.65k
#define PyUnicode_GET_LENGTH(op) PyUnicode_GET_LENGTH(_PyObject_CAST(op))
Line
Count
Source
109
6.65k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6.65k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (5657:9): [True: 10, False: 6.64k]
5658
10
        PyErr_Format(PyExc_TypeError,
5659
10
                     "unsupported format string passed to %.200s.__format__",
5660
10
                     Py_TYPE(self)->tp_name);
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
5661
10
        return NULL;
5662
10
    }
5663
6.64k
    return PyObject_Str(self);
5664
6.65k
}
5665
5666
/*[clinic input]
5667
object.__sizeof__
5668
5669
Size of object in memory, in bytes.
5670
[clinic start generated code]*/
5671
5672
static PyObject *
5673
object___sizeof___impl(PyObject *self)
5674
/*[clinic end generated code: output=73edab332f97d550 input=1200ff3dfe485306]*/
5675
91
{
5676
91
    Py_ssize_t res, isize;
5677
5678
91
    res = 0;
5679
91
    isize = Py_TYPE(self)->tp_itemsize;
Line
Count
Source
138
91
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
91
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91
#  define _Py_CAST(type, expr) ((type)(expr))
5680
91
    if (isize > 0)
  Branch (5680:9): [True: 14, False: 77]
5681
14
        res = Py_SIZE(self) * isize;
Line
Count
Source
147
14
#  define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
Line
Count
Source
109
14
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14
#  define _Py_CAST(type, expr) ((type)(expr))
5682
91
    res += Py_TYPE(self)->tp_basicsize;
Line
Count
Source
138
91
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
91
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
91
#  define _Py_CAST(type, expr) ((type)(expr))
5683
5684
91
    return PyLong_FromSsize_t(res);
5685
91
}
5686
5687
/* __dir__ for generic objects: returns __dict__, __class__,
5688
   and recursively up the __class__.__bases__ chain.
5689
*/
5690
/*[clinic input]
5691
object.__dir__
5692
5693
Default dir() implementation.
5694
[clinic start generated code]*/
5695
5696
static PyObject *
5697
object___dir___impl(PyObject *self)
5698
/*[clinic end generated code: output=66dd48ea62f26c90 input=0a89305bec669b10]*/
5699
11.4k
{
5700
11.4k
    PyObject *result = NULL;
5701
11.4k
    PyObject *dict = NULL;
5702
11.4k
    PyObject *itsclass = NULL;
5703
5704
    /* Get __dict__ (which may or may not be a real dict...) */
5705
11.4k
    if (_PyObject_LookupAttr(self, &_Py_ID(__dict__), &dict) < 0) {
Line
Count
Source
374
11.4k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
11.4k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
11.4k
    _PyRuntime.global_objects.NAME
  Branch (5705:9): [True: 0, False: 11.4k]
5706
0
        return NULL;
5707
0
    }
5708
11.4k
    if (dict == NULL) {
  Branch (5708:9): [True: 9.01k, False: 2.46k]
5709
9.01k
        dict = PyDict_New();
5710
9.01k
    }
5711
2.46k
    else if (!PyDict_Check(dict)) {
Line
Count
Source
18
2.46k
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
Line
Count
Source
782
2.46k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (5711:14): [True: 0, False: 2.46k]
5712
0
        Py_DECREF(dict);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5713
0
        dict = PyDict_New();
5714
0
    }
5715
2.46k
    else {
5716
        /* Copy __dict__ to avoid mutating it. */
5717
2.46k
        PyObject *temp = PyDict_Copy(dict);
5718
2.46k
        Py_DECREF(dict);
Line
Count
Source
548
2.46k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
2.46k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.46k
#  define _Py_CAST(type, expr) ((type)(expr))
5719
2.46k
        dict = temp;
5720
2.46k
    }
5721
5722
11.4k
    if (dict == NULL)
  Branch (5722:9): [True: 0, False: 11.4k]
5723
0
        goto error;
5724
5725
    /* Merge in attrs reachable from its class. */
5726
11.4k
    if (_PyObject_LookupAttr(self, &_Py_ID(__class__), &itsclass) < 0) {
Line
Count
Source
374
11.4k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
11.4k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
11.4k
    _PyRuntime.global_objects.NAME
  Branch (5726:9): [True: 0, False: 11.4k]
5727
0
        goto error;
5728
0
    }
5729
    /* XXX(tomer): Perhaps fall back to Py_TYPE(obj) if no
5730
                   __class__ exists? */
5731
11.4k
    if (itsclass != NULL && merge_class_dict(dict, itsclass) < 0)
  Branch (5731:9): [True: 11.4k, False: 2]
  Branch (5731:29): [True: 0, False: 11.4k]
5732
0
        goto error;
5733
5734
11.4k
    result = PyDict_Keys(dict);
5735
    /* fall through */
5736
11.4k
error:
5737
11.4k
    Py_XDECREF(itsclass);
Line
Count
Source
613
11.4k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
11.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11.4k
#  define _Py_CAST(type, expr) ((type)(expr))
5738
11.4k
    Py_XDECREF(dict);
Line
Count
Source
613
11.4k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
11.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11.4k
#  define _Py_CAST(type, expr) ((type)(expr))
5739
11.4k
    return result;
5740
11.4k
}
5741
5742
static PyMethodDef object_methods[] = {
5743
    OBJECT___REDUCE_EX___METHODDEF
5744
    OBJECT___REDUCE___METHODDEF
5745
    OBJECT___GETSTATE___METHODDEF
5746
    {"__subclasshook__", object_subclasshook, METH_CLASS | METH_VARARGS,
5747
     object_subclasshook_doc},
5748
    {"__init_subclass__", object_init_subclass, METH_CLASS | METH_NOARGS,
5749
     object_init_subclass_doc},
5750
    OBJECT___FORMAT___METHODDEF
5751
    OBJECT___SIZEOF___METHODDEF
5752
    OBJECT___DIR___METHODDEF
5753
    {0}
5754
};
5755
5756
PyDoc_STRVAR(object_doc,
5757
"object()\n--\n\n"
5758
"The base class of the class hierarchy.\n\n"
5759
"When called, it accepts no arguments and returns a new featureless\n"
5760
"instance that has no instance attributes and cannot be given any.\n");
5761
5762
PyTypeObject PyBaseObject_Type = {
5763
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
5764
    "object",                                   /* tp_name */
5765
    sizeof(PyObject),                           /* tp_basicsize */
5766
    0,                                          /* tp_itemsize */
5767
    object_dealloc,                             /* tp_dealloc */
5768
    0,                                          /* tp_vectorcall_offset */
5769
    0,                                          /* tp_getattr */
5770
    0,                                          /* tp_setattr */
5771
    0,                                          /* tp_as_async */
5772
    object_repr,                                /* tp_repr */
5773
    0,                                          /* tp_as_number */
5774
    0,                                          /* tp_as_sequence */
5775
    0,                                          /* tp_as_mapping */
5776
    (hashfunc)_Py_HashPointer,                  /* tp_hash */
5777
    0,                                          /* tp_call */
5778
    object_str,                                 /* tp_str */
5779
    PyObject_GenericGetAttr,                    /* tp_getattro */
5780
    PyObject_GenericSetAttr,                    /* tp_setattro */
5781
    0,                                          /* tp_as_buffer */
5782
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   /* tp_flags */
5783
    object_doc,                                 /* tp_doc */
5784
    0,                                          /* tp_traverse */
5785
    0,                                          /* tp_clear */
5786
    object_richcompare,                         /* tp_richcompare */
5787
    0,                                          /* tp_weaklistoffset */
5788
    0,                                          /* tp_iter */
5789
    0,                                          /* tp_iternext */
5790
    object_methods,                             /* tp_methods */
5791
    0,                                          /* tp_members */
5792
    object_getsets,                             /* tp_getset */
5793
    0,                                          /* tp_base */
5794
    0,                                          /* tp_dict */
5795
    0,                                          /* tp_descr_get */
5796
    0,                                          /* tp_descr_set */
5797
    0,                                          /* tp_dictoffset */
5798
    object_init,                                /* tp_init */
5799
    PyType_GenericAlloc,                        /* tp_alloc */
5800
    object_new,                                 /* tp_new */
5801
    PyObject_Del,                               /* tp_free */
5802
};
5803
5804
5805
static int
5806
type_add_method(PyTypeObject *type, PyMethodDef *meth)
5807
82.7k
{
5808
82.7k
    PyObject *descr;
5809
82.7k
    int isdescr = 1;
5810
82.7k
    if (meth->ml_flags & METH_CLASS) {
Line
Count
Source
90
82.7k
#define METH_CLASS    0x0010
  Branch (5810:9): [True: 3.02k, False: 79.7k]
5811
3.02k
        if (meth->ml_flags & METH_STATIC) {
Line
Count
Source
91
3.02k
#define METH_STATIC   0x0020
  Branch (5811:13): [True: 0, False: 3.02k]
5812
0
            PyErr_SetString(PyExc_ValueError,
5813
0
                    "method cannot be both class and static");
5814
0
            return -1;
5815
0
        }
5816
3.02k
        descr = PyDescr_NewClassMethod(type, meth);
5817
3.02k
    }
5818
79.7k
    else if (meth->ml_flags & METH_STATIC) {
Line
Count
Source
91
79.7k
#define METH_STATIC   0x0020
  Branch (5818:14): [True: 328, False: 79.4k]
5819
328
        PyObject *cfunc = PyCFunction_NewEx(meth, (PyObject*)type, NULL);
Line
Count
Source
73
328
#define PyCFunction_NewEx(ML, SELF, MOD) PyCMethod_New((ML), (SELF), (MOD), NULL)
5820
328
        if (cfunc == NULL) {
  Branch (5820:13): [True: 0, False: 328]
5821
0
            return -1;
5822
0
        }
5823
328
        descr = PyStaticMethod_New(cfunc);
5824
328
        isdescr = 0;  // PyStaticMethod is not PyDescrObject
5825
328
        Py_DECREF(cfunc);
Line
Count
Source
548
328
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
328
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
328
#  define _Py_CAST(type, expr) ((type)(expr))
5826
328
    }
5827
79.4k
    else {
5828
79.4k
        descr = PyDescr_NewMethod(type, meth);
5829
79.4k
    }
5830
82.7k
    if (descr == NULL) {
  Branch (5830:9): [True: 0, False: 82.7k]
5831
0
        return -1;
5832
0
    }
5833
5834
82.7k
    PyObject *name;
5835
82.7k
    if (isdescr) {
  Branch (5835:9): [True: 82.4k, False: 328]
5836
82.4k
        name = PyDescr_NAME(descr);
Line
Count
Source
36
82.4k
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
5837
82.4k
    }
5838
328
    else {
5839
328
        name = PyUnicode_FromString(meth->ml_name);
5840
328
        if (name == NULL) {
  Branch (5840:13): [True: 0, False: 328]
5841
0
            Py_DECREF(descr);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5842
0
            return -1;
5843
0
        }
5844
328
    }
5845
5846
82.7k
    int err;
5847
82.7k
    if (!(meth->ml_flags & METH_COEXIST)) {
Line
Count
Source
98
82.7k
#define METH_COEXIST   0x0040
  Branch (5847:9): [True: 82.2k, False: 529]
5848
82.2k
        err = PyDict_SetDefault(type->tp_dict, name, descr) == NULL;
5849
82.2k
    }
5850
529
    else {
5851
529
        err = PyDict_SetItem(type->tp_dict, name, descr) < 0;
5852
529
    }
5853
82.7k
    if (!isdescr) {
  Branch (5853:9): [True: 328, False: 82.4k]
5854
328
        Py_DECREF(name);
Line
Count
Source
548
328
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
328
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
328
#  define _Py_CAST(type, expr) ((type)(expr))
5855
328
    }
5856
82.7k
    Py_DECREF(descr);
Line
Count
Source
548
82.7k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
82.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
82.7k
#  define _Py_CAST(type, expr) ((type)(expr))
5857
82.7k
    if (err) {
  Branch (5857:9): [True: 0, False: 82.7k]
5858
0
        return -1;
5859
0
    }
5860
82.7k
    return 0;
5861
82.7k
}
5862
5863
5864
/* Add the methods from tp_methods to the __dict__ in a type object */
5865
static int
5866
type_add_methods(PyTypeObject *type)
5867
114k
{
5868
114k
    PyMethodDef *meth = type->tp_methods;
5869
114k
    if (meth == NULL) {
  Branch (5869:9): [True: 97.4k, False: 17.3k]
5870
97.4k
        return 0;
5871
97.4k
    }
5872
5873
100k
    for (; meth->ml_name != NULL; meth++) {
  Branch (5873:12): [True: 82.7k, False: 17.3k]
5874
82.7k
        if (type_add_method(type, meth) < 0) {
  Branch (5874:13): [True: 0, False: 82.7k]
5875
0
            return -1;
5876
0
        }
5877
82.7k
    }
5878
17.3k
    return 0;
5879
17.3k
}
5880
5881
5882
static int
5883
type_add_members(PyTypeObject *type)
5884
114k
{
5885
114k
    PyMemberDef *memb = type->tp_members;
5886
114k
    if (memb == NULL) {
  Branch (5886:9): [True: 17.2k, False: 97.5k]
5887
17.2k
        return 0;
5888
17.2k
    }
5889
5890
97.5k
    PyObject *dict = type->tp_dict;
5891
142k
    for (; memb->name != NULL; memb++) {
  Branch (5891:12): [True: 44.6k, False: 97.5k]
5892
44.6k
        PyObject *descr = PyDescr_NewMember(type, memb);
5893
44.6k
        if (descr == NULL)
  Branch (5893:13): [True: 0, False: 44.6k]
5894
0
            return -1;
5895
5896
44.6k
        if (PyDict_SetDefault(dict, PyDescr_NAME(descr), descr) == NULL) {
Line
Count
Source
36
44.6k
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
  Branch (5896:13): [True: 0, False: 44.6k]
5897
0
            Py_DECREF(descr);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5898
0
            return -1;
5899
0
        }
5900
44.6k
        Py_DECREF(descr);
Line
Count
Source
548
44.6k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
44.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
44.6k
#  define _Py_CAST(type, expr) ((type)(expr))
5901
44.6k
    }
5902
97.5k
    return 0;
5903
97.5k
}
5904
5905
5906
static int
5907
type_add_getset(PyTypeObject *type)
5908
114k
{
5909
114k
    PyGetSetDef *gsp = type->tp_getset;
5910
114k
    if (gsp == NULL) {
  Branch (5910:9): [True: 71.0k, False: 43.7k]
5911
71.0k
        return 0;
5912
71.0k
    }
5913
5914
43.7k
    PyObject *dict = type->tp_dict;
5915
132k
    for (; gsp->name != NULL; gsp++) {
  Branch (5915:12): [True: 88.4k, False: 43.7k]
5916
88.4k
        PyObject *descr = PyDescr_NewGetSet(type, gsp);
5917
88.4k
        if (descr == NULL) {
  Branch (5917:13): [True: 0, False: 88.4k]
5918
0
            return -1;
5919
0
        }
5920
5921
88.4k
        if (PyDict_SetDefault(dict, PyDescr_NAME(descr), descr) == NULL) {
Line
Count
Source
36
88.4k
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
  Branch (5921:13): [True: 0, False: 88.4k]
5922
0
            Py_DECREF(descr);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
5923
0
            return -1;
5924
0
        }
5925
88.4k
        Py_DECREF(descr);
Line
Count
Source
548
88.4k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
88.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
88.4k
#  define _Py_CAST(type, expr) ((type)(expr))
5926
88.4k
    }
5927
43.7k
    return 0;
5928
43.7k
}
5929
5930
5931
static void
5932
inherit_special(PyTypeObject *type, PyTypeObject *base)
5933
114k
{
5934
    /* Copying tp_traverse and tp_clear is connected to the GC flags */
5935
114k
    if (!(type->tp_flags & Py_TPFLAGS_HAVE_GC) &&
Line
Count
Source
394
114k
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (5935:9): [True: 4.36k, False: 110k]
5936
114k
        (base->tp_flags & Py_TPFLAGS_HAVE_GC) &&
Line
Count
Source
394
4.36k
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (5936:9): [True: 527, False: 3.84k]
5937
114k
        (!type->tp_traverse && !type->tp_clear)) {
  Branch (5937:10): [True: 527, False: 0]
  Branch (5937:32): [True: 527, False: 0]
5938
527
        type->tp_flags |= Py_TPFLAGS_HAVE_GC;
Line
Count
Source
394
527
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
5939
527
        if (type->tp_traverse == NULL)
  Branch (5939:13): [True: 527, False: 0]
5940
527
            type->tp_traverse = base->tp_traverse;
5941
527
        if (type->tp_clear == NULL)
  Branch (5941:13): [True: 527, False: 0]
5942
527
            type->tp_clear = base->tp_clear;
5943
527
    }
5944
114k
    type->tp_flags |= (base->tp_flags & Py_TPFLAGS_MANAGED_DICT);
Line
Count
Source
359
114k
#define Py_TPFLAGS_MANAGED_DICT (1 << 4)
5945
5946
114k
    if (type->tp_basicsize == 0)
  Branch (5946:9): [True: 687, False: 114k]
5947
687
        type->tp_basicsize = base->tp_basicsize;
5948
5949
    /* Copy other non-function slots */
5950
5951
114k
#define COPYVAL(SLOT) \
5952
344k
    if (type->SLOT == 0) { type->SLOT = base->SLOT; }
5953
5954
114k
    COPYVAL(tp_itemsize);
Line
Count
Source
5952
114k
    if (type->SLOT == 0) { type->SLOT = base->SLOT; }
  Branch (5952:9): [True: 106k, False: 7.94k]
5955
114k
    COPYVAL(tp_weaklistoffset);
Line
Count
Source
5952
114k
    if (type->SLOT == 0) { type->SLOT = base->SLOT; }
  Branch (5952:9): [True: 72.9k, False: 41.7k]
5956
114k
    COPYVAL(tp_dictoffset);
Line
Count
Source
5952
114k
    if (type->SLOT == 0) { type->SLOT = base->SLOT; }
  Branch (5952:9): [True: 70.7k, False: 44.0k]
5957
114k
#undef COPYVAL
5958
5959
    /* Setup fast subclass flags */
5960
114k
    if (PyType_IsSubtype(base, (PyTypeObject*)PyExc_BaseException)) {
  Branch (5960:9): [True: 9.57k, False: 105k]
5961
9.57k
        type->tp_flags |= Py_TPFLAGS_BASE_EXC_SUBCLASS;
Line
Count
Source
424
9.57k
#define Py_TPFLAGS_BASE_EXC_SUBCLASS    (1UL << 30)
5962
9.57k
    }
5963
105k
    else if (PyType_IsSubtype(base, &PyType_Type)) {
  Branch (5963:14): [True: 526, False: 104k]
5964
526
        type->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS;
Line
Count
Source
425
526
#define Py_TPFLAGS_TYPE_SUBCLASS        (1UL << 31)
5965
526
    }
5966
104k
    else if (PyType_IsSubtype(base, &PyLong_Type)) {
  Branch (5966:14): [True: 1.65k, False: 102k]
5967
1.65k
        type->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS;
Line
Count
Source
418
1.65k
#define Py_TPFLAGS_LONG_SUBCLASS        (1UL << 24)
5968
1.65k
    }
5969
102k
    else if (PyType_IsSubtype(base, &PyBytes_Type)) {
  Branch (5969:14): [True: 88, False: 102k]
5970
88
        type->tp_flags |= Py_TPFLAGS_BYTES_SUBCLASS;
Line
Count
Source
421
88
#define Py_TPFLAGS_BYTES_SUBCLASS       (1UL << 27)
5971
88
    }
5972
102k
    else if (PyType_IsSubtype(base, &PyUnicode_Type)) {
  Branch (5972:14): [True: 7.60k, False: 95.2k]
5973
7.60k
        type->tp_flags |= Py_TPFLAGS_UNICODE_SUBCLASS;
Line
Count
Source
422
7.60k
#define Py_TPFLAGS_UNICODE_SUBCLASS     (1UL << 28)
5974
7.60k
    }
5975
95.2k
    else if (PyType_IsSubtype(base, &PyTuple_Type)) {
  Branch (5975:14): [True: 4.35k, False: 90.9k]
5976
4.35k
        type->tp_flags |= Py_TPFLAGS_TUPLE_SUBCLASS;
Line
Count
Source
420
4.35k
#define Py_TPFLAGS_TUPLE_SUBCLASS       (1UL << 26)
5977
4.35k
    }
5978
90.9k
    else if (PyType_IsSubtype(base, &PyList_Type)) {
  Branch (5978:14): [True: 247, False: 90.6k]
5979
247
        type->tp_flags |= Py_TPFLAGS_LIST_SUBCLASS;
Line
Count
Source
419
247
#define Py_TPFLAGS_LIST_SUBCLASS        (1UL << 25)
5980
247
    }
5981
90.6k
    else if (PyType_IsSubtype(base, &PyDict_Type)) {
  Branch (5981:14): [True: 601, False: 90.0k]
5982
601
        type->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS;
Line
Count
Source
423
601
#define Py_TPFLAGS_DICT_SUBCLASS        (1UL << 29)
5983
601
    }
5984
114k
    if (PyType_HasFeature(base, _Py_TPFLAGS_MATCH_SELF)) {
Line
Count
Source
415
114k
#define _Py_TPFLAGS_MATCH_SELF (1UL << 22)
  Branch (5984:9): [True: 15.1k, False: 99.5k]
5985
15.1k
        type->tp_flags |= _Py_TPFLAGS_MATCH_SELF;
Line
Count
Source
415
15.1k
#define _Py_TPFLAGS_MATCH_SELF (1UL << 22)
5986
15.1k
    }
5987
114k
}
5988
5989
static int
5990
overrides_hash(PyTypeObject *type)
5991
109k
{
5992
109k
    PyObject *dict = type->tp_dict;
5993
5994
109k
    assert(dict != NULL);
5995
109k
    int r = PyDict_Contains(dict, &_Py_ID(__eq__));
Line
Count
Source
374
109k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
109k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
109k
    _PyRuntime.global_objects.NAME
5996
109k
    if (r == 0) {
  Branch (5996:9): [True: 89.2k, False: 20.2k]
5997
89.2k
        r = PyDict_Contains(dict, &_Py_ID(__hash__));
Line
Count
Source
374
89.2k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
89.2k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
89.2k
    _PyRuntime.global_objects.NAME
5998
89.2k
    }
5999
109k
    return r;
6000
109k
}
6001
6002
static int
6003
inherit_slots(PyTypeObject *type, PyTypeObject *base)
6004
305k
{
6005
305k
    PyTypeObject *basebase;
6006
6007
305k
#undef SLOTDEFINED
6008
305k
#undef COPYSLOT
6009
305k
#undef COPYNUM
6010
305k
#undef COPYSEQ
6011
305k
#undef COPYMAP
6012
305k
#undef COPYBUF
6013
6014
305k
#define SLOTDEFINED(SLOT) \
6015
10.4M
    (base->SLOT != 0 && \
6016
10.4M
     (basebase == NULL || base->SLOT != basebase->SLOT))
6017
6018
305k
#define COPYSLOT(SLOT) \
6019
12.1M
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
6020
6021
414k
#define COPYASYNC(SLOT) COPYSLOT(tp_as_async->SLOT)
6022
5.29M
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
6023
1.21M
#define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT)
6024
455k
#define COPYMAP(SLOT) COPYSLOT(tp_as_mapping->SLOT)
6025
305k
#define COPYBUF(SLOT) COPYSLOT(tp_as_buffer->SLOT)
6026
6027
    /* This won't inherit indirect slots (from tp_as_number etc.)
6028
       if type doesn't provide the space. */
6029
6030
305k
    if (type->tp_as_number != NULL && base->tp_as_number != NULL) {
  Branch (6030:9): [True: 263k, False: 41.6k]
  Branch (6030:39): [True: 151k, False: 112k]
6031
151k
        basebase = base->tp_base;
6032
151k
        if (basebase->tp_as_number == NULL)
  Branch (6032:13): [True: 72.7k, False: 78.6k]
6033
72.7k
            basebase = NULL;
6034
151k
        COPYNUM(nb_add);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
146k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 5.67k, False: 141k]
6016
146k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.81k, False: 2.85k]
  Branch (6016:27): [True: 77, False: 2.77k]
  Branch (6019:9): [True: 146k, False: 4.57k]
6035
151k
        COPYNUM(nb_subtract);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
142k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 6.74k, False: 135k]
6016
142k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.85k, False: 3.88k]
  Branch (6016:27): [True: 1.09k, False: 2.78k]
  Branch (6019:9): [True: 142k, False: 9.07k]
6036
151k
        COPYNUM(nb_multiply);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 4.37k, False: 143k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.21k, False: 2.16k]
  Branch (6016:27): [True: 25, False: 2.13k]
  Branch (6019:9): [True: 147k, False: 3.72k]
6037
151k
        COPYNUM(nb_remainder);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
146k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 19.3k, False: 127k]
6016
146k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 9.89k, False: 9.44k]
  Branch (6016:27): [True: 16, False: 9.42k]
  Branch (6019:9): [True: 146k, False: 4.87k]
6038
151k
        COPYNUM(nb_divmod);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 4.32k, False: 143k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.18k, False: 2.13k]
  Branch (6016:27): [True: 14, False: 2.12k]
  Branch (6019:9): [True: 147k, False: 3.67k]
6039
151k
        COPYNUM(nb_power);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 4.35k, False: 143k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.19k, False: 2.15k]
  Branch (6016:27): [True: 15, False: 2.13k]
  Branch (6019:9): [True: 147k, False: 3.65k]
6040
151k
        COPYNUM(nb_negative);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 4.36k, False: 143k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.21k, False: 2.15k]
  Branch (6016:27): [True: 20, False: 2.13k]
  Branch (6019:9): [True: 147k, False: 3.66k]
6041
151k
        COPYNUM(nb_positive);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 4.36k, False: 143k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.21k, False: 2.15k]
  Branch (6016:27): [True: 20, False: 2.13k]
  Branch (6019:9): [True: 147k, False: 3.66k]
6042
151k
        COPYNUM(nb_absolute);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 4.35k, False: 143k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.20k, False: 2.15k]
  Branch (6016:27): [True: 15, False: 2.13k]
  Branch (6019:9): [True: 147k, False: 3.65k]
6043
151k
        COPYNUM(nb_bool);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 5.85k, False: 141k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 3.29k, False: 2.55k]
  Branch (6016:27): [True: 309, False: 2.24k]
  Branch (6019:9): [True: 147k, False: 4.04k]
6044
151k
        COPYNUM(nb_invert);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 2.90k, False: 144k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 1.05k, False: 1.85k]
  Branch (6016:27): [True: 828, False: 1.02k]
  Branch (6019:9): [True: 147k, False: 3.76k]
6045
151k
        COPYNUM(nb_lshift);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
148k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 3.13k, False: 145k]
6016
148k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 1.62k, False: 1.51k]
  Branch (6016:27): [True: 0, False: 1.51k]
  Branch (6019:9): [True: 148k, False: 2.93k]
6046
151k
        COPYNUM(nb_rshift);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
148k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 3.13k, False: 145k]
6016
148k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 1.62k, False: 1.51k]
  Branch (6016:27): [True: 0, False: 1.51k]
  Branch (6019:9): [True: 148k, False: 2.93k]
6047
151k
        COPYNUM(nb_and);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
142k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 3.93k, False: 138k]
6016
142k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 1.02k, False: 2.90k]
  Branch (6016:27): [True: 1.87k, False: 1.03k]
  Branch (6019:9): [True: 142k, False: 8.42k]
6048
151k
        COPYNUM(nb_xor);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
142k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 3.92k, False: 139k]
6016
142k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 1.02k, False: 2.90k]
  Branch (6016:27): [True: 1.86k, False: 1.03k]
  Branch (6019:9): [True: 142k, False: 8.41k]
6049
151k
        COPYNUM(nb_or);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
142k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 5.34k, False: 137k]
6016
142k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.23k, False: 3.10k]
  Branch (6016:27): [True: 2.01k, False: 1.08k]
  Branch (6019:9): [True: 142k, False: 9.00k]
6050
151k
        COPYNUM(nb_int);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 4.30k, False: 143k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.18k, False: 2.12k]
  Branch (6016:27): [True: 20, False: 2.10k]
  Branch (6019:9): [True: 147k, False: 3.70k]
6051
151k
        COPYNUM(nb_float);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 4.32k, False: 143k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.18k, False: 2.14k]
  Branch (6016:27): [True: 16, False: 2.12k]
  Branch (6019:9): [True: 147k, False: 3.68k]
6052
151k
        COPYNUM(nb_inplace_add);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
150k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 183, False: 150k]
6016
150k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 53, False: 130]
  Branch (6016:27): [True: 113, False: 17]
  Branch (6019:9): [True: 150k, False: 656]
6053
151k
        COPYNUM(nb_inplace_subtract);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 40, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 24, False: 16]
  Branch (6016:27): [True: 14, False: 2]
  Branch (6019:9): [True: 151k, False: 53]
6054
151k
        COPYNUM(nb_inplace_multiply);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 8, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 8]
  Branch (6016:27): [True: 8, False: 0]
  Branch (6019:9): [True: 151k, False: 54]
6055
151k
        COPYNUM(nb_inplace_remainder);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 0, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 0]
  Branch (6016:27): [True: 0, False: 0]
  Branch (6019:9): [True: 151k, False: 0]
6056
151k
        COPYNUM(nb_inplace_power);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 2, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2, False: 0]
  Branch (6016:27): [True: 0, False: 0]
  Branch (6019:9): [True: 151k, False: 0]
6057
151k
        COPYNUM(nb_inplace_lshift);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 0, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 0]
  Branch (6016:27): [True: 0, False: 0]
  Branch (6019:9): [True: 151k, False: 0]
6058
151k
        COPYNUM(nb_inplace_rshift);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 0, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 0]
  Branch (6016:27): [True: 0, False: 0]
  Branch (6019:9): [True: 151k, False: 0]
6059
151k
        COPYNUM(nb_inplace_and);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 40, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 24, False: 16]
  Branch (6016:27): [True: 14, False: 2]
  Branch (6019:9): [True: 151k, False: 53]
6060
151k
        COPYNUM(nb_inplace_xor);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 35, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 24, False: 11]
  Branch (6016:27): [True: 9, False: 2]
  Branch (6019:9): [True: 151k, False: 46]
6061
151k
        COPYNUM(nb_inplace_or);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
150k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 589, False: 150k]
6016
150k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 469, False: 120]
  Branch (6016:27): [True: 91, False: 29]
  Branch (6019:9): [True: 150k, False: 437]
6062
151k
        COPYNUM(nb_true_divide);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 4.39k, False: 143k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.22k, False: 2.17k]
  Branch (6016:27): [True: 30, False: 2.14k]
  Branch (6019:9): [True: 147k, False: 3.68k]
6063
151k
        COPYNUM(nb_floor_divide);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 4.32k, False: 143k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.18k, False: 2.13k]
  Branch (6016:27): [True: 14, False: 2.12k]
  Branch (6019:9): [True: 147k, False: 3.67k]
6064
151k
        COPYNUM(nb_inplace_true_divide);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 0, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 0]
  Branch (6016:27): [True: 0, False: 0]
  Branch (6019:9): [True: 151k, False: 0]
6065
151k
        COPYNUM(nb_inplace_floor_divide);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 0, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 0]
  Branch (6016:27): [True: 0, False: 0]
  Branch (6019:9): [True: 151k, False: 0]
6066
151k
        COPYNUM(nb_index);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
148k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 3.13k, False: 145k]
6016
148k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 1.62k, False: 1.51k]
  Branch (6016:27): [True: 0, False: 1.51k]
  Branch (6019:9): [True: 148k, False: 2.93k]
6067
151k
        COPYNUM(nb_matrix_multiply);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 1, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 1, False: 0]
  Branch (6016:27): [True: 0, False: 0]
  Branch (6019:9): [True: 151k, False: 0]
6068
151k
        COPYNUM(nb_inplace_matrix_multiply);
Line
Count
Source
6022
151k
#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 0, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 0]
  Branch (6016:27): [True: 0, False: 0]
  Branch (6019:9): [True: 151k, False: 0]
6069
151k
    }
6070
6071
305k
    if (type->tp_as_async != NULL && base->tp_as_async != NULL) {
  Branch (6071:9): [True: 261k, False: 43.9k]
  Branch (6071:38): [True: 138k, False: 123k]
6072
138k
        basebase = base->tp_base;
6073
138k
        if (basebase->tp_as_async == NULL)
  Branch (6073:13): [True: 69.0k, False: 69.1k]
6074
69.0k
            basebase = NULL;
6075
138k
        COPYASYNC(am_await);
Line
Count
Source
6021
138k
#define COPYASYNC(SLOT) COPYSLOT(tp_as_async->SLOT)
Line
Count
Source
6019
138k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
138k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 323, False: 137k]
6016
138k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 315, False: 8]
  Branch (6016:27): [True: 0, False: 8]
  Branch (6019:9): [True: 138k, False: 3]
6076
138k
        COPYASYNC(am_aiter);
Line
Count
Source
6021
138k
#define COPYASYNC(SLOT) COPYSLOT(tp_as_async->SLOT)
Line
Count
Source
6019
138k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
138k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 867, False: 137k]
6016
138k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 570, False: 297]
  Branch (6016:27): [True: 0, False: 297]
  Branch (6019:9): [True: 138k, False: 3]
6077
138k
        COPYASYNC(am_anext);
Line
Count
Source
6021
138k
#define COPYASYNC(SLOT) COPYSLOT(tp_as_async->SLOT)
Line
Count
Source
6019
138k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
137k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 297, False: 137k]
6016
137k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 297]
  Branch (6016:27): [True: 290, False: 7]
  Branch (6019:9): [True: 137k, False: 293]
6078
138k
    }
6079
6080
305k
    if (type->tp_as_sequence != NULL && base->tp_as_sequence != NULL) {
  Branch (6080:9): [True: 263k, False: 41.7k]
  Branch (6080:41): [True: 151k, False: 111k]
6081
151k
        basebase = base->tp_base;
6082
151k
        if (basebase->tp_as_sequence == NULL)
  Branch (6082:13): [True: 75.0k, False: 76.5k]
6083
75.0k
            basebase = NULL;
6084
151k
        COPYSEQ(sq_length);
Line
Count
Source
6023
151k
#define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
137k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 31.8k, False: 105k]
6016
137k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 15.9k, False: 15.9k]
  Branch (6016:27): [True: 1.14k, False: 14.7k]
  Branch (6019:9): [True: 137k, False: 14.0k]
6085
151k
        COPYSEQ(sq_concat);
Line
Count
Source
6023
151k
#define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
150k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 18.9k, False: 131k]
6016
150k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 11.5k, False: 7.45k]
  Branch (6016:27): [True: 0, False: 7.45k]
  Branch (6019:9): [True: 150k, False: 1.50k]
6086
151k
        COPYSEQ(sq_repeat);
Line
Count
Source
6023
151k
#define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
150k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 18.9k, False: 131k]
6016
150k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 11.5k, False: 7.45k]
  Branch (6016:27): [True: 0, False: 7.45k]
  Branch (6019:9): [True: 150k, False: 1.50k]
6087
151k
        COPYSEQ(sq_item);
Line
Count
Source
6023
151k
#define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
134k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 15.9k, False: 118k]
6016
134k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 5.48k, False: 10.5k]
  Branch (6016:27): [True: 9.03k, False: 1.47k]
  Branch (6019:9): [True: 134k, False: 16.8k]
6088
151k
        COPYSEQ(sq_ass_item);
Line
Count
Source
6023
151k
#define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 2.95k, False: 144k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 1.53k, False: 1.42k]
  Branch (6016:27): [True: 744, False: 679]
  Branch (6019:9): [True: 147k, False: 4.09k]
6089
151k
        COPYSEQ(sq_contains);
Line
Count
Source
6023
151k
#define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
134k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 27.2k, False: 107k]
6016
134k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 12.8k, False: 14.3k]
  Branch (6016:27): [True: 4.22k, False: 10.1k]
  Branch (6019:9): [True: 134k, False: 17.3k]
6090
151k
        COPYSEQ(sq_inplace_concat);
Line
Count
Source
6023
151k
#define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 376, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 312, False: 64]
  Branch (6016:27): [True: 0, False: 64]
  Branch (6019:9): [True: 151k, False: 18]
6091
151k
        COPYSEQ(sq_inplace_repeat);
Line
Count
Source
6023
151k
#define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
151k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 377, False: 151k]
6016
151k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 312, False: 65]
  Branch (6016:27): [True: 0, False: 65]
  Branch (6019:9): [True: 151k, False: 18]
6092
151k
    }
6093
6094
305k
    if (type->tp_as_mapping != NULL && base->tp_as_mapping != NULL) {
  Branch (6094:9): [True: 263k, False: 41.8k]
  Branch (6094:40): [True: 151k, False: 111k]
6095
151k
        basebase = base->tp_base;
6096
151k
        if (basebase->tp_as_mapping == NULL)
  Branch (6096:13): [True: 75.2k, False: 76.5k]
6097
75.2k
            basebase = NULL;
6098
151k
        COPYMAP(mp_length);
Line
Count
Source
6024
151k
#define COPYMAP(SLOT) COPYSLOT(tp_as_mapping->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
137k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 32.3k, False: 105k]
6016
137k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 16.4k, False: 15.9k]
  Branch (6016:27): [True: 1.10k, False: 14.8k]
  Branch (6019:9): [True: 137k, False: 13.9k]
6099
151k
        COPYMAP(mp_subscript);
Line
Count
Source
6024
151k
#define COPYMAP(SLOT) COPYSLOT(tp_as_mapping->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
142k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 24.0k, False: 118k]
6016
142k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 13.5k, False: 10.5k]
  Branch (6016:27): [True: 1.76k, False: 8.75k]
  Branch (6019:9): [True: 142k, False: 9.60k]
6100
151k
        COPYMAP(mp_ass_subscript);
Line
Count
Source
6024
151k
#define COPYMAP(SLOT) COPYSLOT(tp_as_mapping->SLOT)
Line
Count
Source
6019
151k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
147k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 2.53k, False: 145k]
6016
147k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 1.07k, False: 1.46k]
  Branch (6016:27): [True: 707, False: 753]
  Branch (6019:9): [True: 147k, False: 4.18k]
6101
151k
    }
6102
6103
305k
    if (type->tp_as_buffer != NULL && base->tp_as_buffer != NULL) {
  Branch (6103:9): [True: 261k, False: 44.0k]
  Branch (6103:39): [True: 141k, False: 119k]
6104
141k
        basebase = base->tp_base;
6105
141k
        if (basebase->tp_as_buffer == NULL)
  Branch (6105:13): [True: 70.5k, False: 70.7k]
6106
70.5k
            basebase = NULL;
6107
141k
        COPYBUF(bf_getbuffer);
Line
Count
Source
6025
141k
#define COPYBUF(SLOT) COPYSLOT(tp_as_buffer->SLOT)
Line
Count
Source
6019
141k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
141k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 3.24k, False: 138k]
6016
141k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 1.64k, False: 1.59k]
  Branch (6016:27): [True: 0, False: 1.59k]
  Branch (6019:9): [True: 141k, False: 6]
6108
141k
        COPYBUF(bf_releasebuffer);
Line
Count
Source
6025
141k
#define COPYBUF(SLOT) COPYSLOT(tp_as_buffer->SLOT)
Line
Count
Source
6019
141k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
141k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 58, False: 141k]
6016
141k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 58, False: 0]
  Branch (6016:27): [True: 0, False: 0]
  Branch (6019:9): [True: 141k, False: 0]
6109
141k
    }
6110
6111
305k
    basebase = base->tp_base;
6112
6113
305k
    COPYSLOT(tp_dealloc);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
1.12k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 1.12k, False: 0]
6016
1.12k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 597, False: 530]
  Branch (6016:27): [True: 526, False: 4]
  Branch (6019:9): [True: 1.12k, False: 303k]
6114
305k
    if (type->tp_getattr == NULL && type->tp_getattro == NULL) {
  Branch (6114:9): [True: 305k, False: 0]
  Branch (6114:37): [True: 99.6k, False: 205k]
6115
99.6k
        type->tp_getattr = base->tp_getattr;
6116
99.6k
        type->tp_getattro = base->tp_getattro;
6117
99.6k
    }
6118
305k
    if (type->tp_setattr == NULL && type->tp_setattro == NULL) {
  Branch (6118:9): [True: 305k, False: 19]
  Branch (6118:37): [True: 106k, False: 198k]
6119
106k
        type->tp_setattr = base->tp_setattr;
6120
106k
        type->tp_setattro = base->tp_setattro;
6121
106k
    }
6122
305k
    COPYSLOT(tp_repr);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
186k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 186k, False: 1]
6016
186k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 59.4k, False: 126k]
  Branch (6016:27): [True: 39.1k, False: 87.5k]
  Branch (6019:9): [True: 186k, False: 118k]
6123
    /* tp_hash see tp_richcompare */
6124
305k
    {
6125
        /* Always inherit tp_vectorcall_offset to support PyVectorcall_Call().
6126
         * If Py_TPFLAGS_HAVE_VECTORCALL is not inherited, then vectorcall
6127
         * won't be used automatically. */
6128
305k
        COPYSLOT(tp_vectorcall_offset);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
303k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 949, False: 302k]
6016
303k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 949]
  Branch (6016:27): [True: 917, False: 32]
  Branch (6019:9): [True: 303k, False: 2.00k]
6129
6130
        /* Inherit Py_TPFLAGS_HAVE_VECTORCALL for non-heap types
6131
        * if tp_call is not overridden */
6132
305k
        if (!type->tp_call &&
  Branch (6132:13): [True: 255k, False: 49.3k]
6133
305k
            _PyType_HasFeature(base, Py_TPFLAGS_HAVE_VECTORCALL) &&
Line
Count
Source
382
255k
#define Py_TPFLAGS_HAVE_VECTORCALL (1UL << 11)
  Branch (6133:13): [True: 916, False: 254k]
6134
305k
            _PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE))
Line
Count
Source
372
916
#define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
  Branch (6134:13): [True: 80, False: 836]
6135
80
        {
6136
80
            type->tp_flags |= Py_TPFLAGS_HAVE_VECTORCALL;
Line
Count
Source
382
80
#define Py_TPFLAGS_HAVE_VECTORCALL (1UL << 11)
6137
80
        }
6138
305k
        COPYSLOT(tp_call);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
255k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 23.1k, False: 232k]
6016
255k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 23.1k]
  Branch (6016:27): [True: 15.8k, False: 7.30k]
  Branch (6019:9): [True: 255k, False: 49.3k]
6139
305k
    }
6140
305k
    COPYSLOT(tp_str);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
250k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 250k, False: 1]
6016
250k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 83.4k, False: 167k]
  Branch (6016:27): [True: 23.2k, False: 143k]
  Branch (6019:9): [True: 250k, False: 54.4k]
6141
305k
    {
6142
        /* Copy comparison-related slots only when
6143
           not overriding them anywhere */
6144
305k
        if (type->tp_richcompare == NULL &&
  Branch (6144:13): [True: 112k, False: 192k]
6145
305k
            type->tp_hash == NULL)
  Branch (6145:13): [True: 109k, False: 3.37k]
6146
109k
        {
6147
109k
            int r = overrides_hash(type);
6148
109k
            if (r < 0) {
  Branch (6148:17): [True: 0, False: 109k]
6149
0
                return -1;
6150
0
            }
6151
109k
            if (!r) {
  Branch (6151:17): [True: 88.6k, False: 20.9k]
6152
88.6k
                type->tp_richcompare = base->tp_richcompare;
6153
88.6k
                type->tp_hash = base->tp_hash;
6154
88.6k
            }
6155
109k
        }
6156
305k
    }
6157
305k
    {
6158
305k
        COPYSLOT(tp_iter);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
256k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 36.4k, False: 219k]
6016
256k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 36.4k]
  Branch (6016:27): [True: 21.5k, False: 14.8k]
  Branch (6019:9): [True: 256k, False: 48.8k]
6159
305k
        COPYSLOT(tp_iternext);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
210k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 111k, False: 98.6k]
6016
210k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 111k]
  Branch (6016:27): [True: 47.4k, False: 64.5k]
  Branch (6019:9): [True: 210k, False: 94.4k]
6160
305k
    }
6161
305k
    {
6162
305k
        COPYSLOT(tp_descr_get);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
302k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 909, False: 301k]
6016
302k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 909]
  Branch (6016:27): [True: 909, False: 0]
  Branch (6019:9): [True: 302k, False: 2.22k]
6163
        /* Inherit Py_TPFLAGS_METHOD_DESCRIPTOR if tp_descr_get was inherited,
6164
         * but only for extension types */
6165
305k
        if (base->tp_descr_get &&
  Branch (6165:13): [True: 910, False: 304k]
6166
305k
            type->tp_descr_get == base->tp_descr_get &&
  Branch (6166:13): [True: 909, False: 1]
6167
305k
            _PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE) &&
Line
Count
Source
372
909
#define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
  Branch (6167:13): [True: 2, False: 907]
6168
305k
            _PyType_HasFeature(base, Py_TPFLAGS_METHOD_DESCRIPTOR))
Line
Count
Source
404
2
#define Py_TPFLAGS_METHOD_DESCRIPTOR (1UL << 17)
  Branch (6168:13): [True: 2, False: 0]
6169
2
        {
6170
2
            type->tp_flags |= Py_TPFLAGS_METHOD_DESCRIPTOR;
Line
Count
Source
404
2
#define Py_TPFLAGS_METHOD_DESCRIPTOR (1UL << 17)
6171
2
        }
6172
305k
        COPYSLOT(tp_descr_set);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
304k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 345, False: 304k]
6016
304k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 345]
  Branch (6016:27): [True: 345, False: 0]
  Branch (6019:9): [True: 304k, False: 717]
6173
305k
        COPYSLOT(tp_dictoffset);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
50.6k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 0, False: 50.6k]
6016
50.6k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 0]
  Branch (6016:27): [True: 0, False: 0]
  Branch (6019:9): [True: 50.6k, False: 254k]
6174
305k
        COPYSLOT(tp_init);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
212k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 212k, False: 1]
6016
212k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 66.3k, False: 146k]
  Branch (6016:27): [True: 35.0k, False: 111k]
  Branch (6019:9): [True: 212k, False: 92.2k]
6175
305k
        COPYSLOT(tp_alloc);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
36.7k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 36.7k, False: 0]
6016
36.7k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 19.1k, False: 17.5k]
  Branch (6016:27): [True: 2, False: 17.5k]
  Branch (6019:9): [True: 36.7k, False: 268k]
6176
305k
        COPYSLOT(tp_is_gc);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
304k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 558, False: 303k]
6016
304k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 558]
  Branch (6016:27): [True: 526, False: 32]
  Branch (6019:9): [True: 304k, False: 636]
6177
305k
        COPYSLOT(tp_finalize);
Line
Count
Source
6019
305k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
300k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 5.24k, False: 295k]
6016
300k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 0, False: 5.24k]
  Branch (6016:27): [True: 2.33k, False: 2.90k]
  Branch (6019:9): [True: 300k, False: 4.20k]
6178
305k
        if ((type->tp_flags & Py_TPFLAGS_HAVE_GC) ==
Line
Count
Source
394
305k
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (6178:13): [True: 180k, False: 124k]
6179
305k
            (base->tp_flags & Py_TPFLAGS_HAVE_GC)) {
Line
Count
Source
394
305k
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
6180
            /* They agree about gc. */
6181
180k
            COPYSLOT(tp_free);
Line
Count
Source
6019
180k
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
Line
Count
Source
6015
20.0k
    (base->SLOT != 0 && \
  Branch (6015:6): [True: 20.0k, False: 0]
6016
20.0k
     (basebase == NULL || base->SLOT != basebase->SLOT))
  Branch (6016:7): [True: 2.36k, False: 17.6k]
  Branch (6016:27): [True: 9.06k, False: 8.58k]
  Branch (6019:9): [True: 20.0k, False: 160k]
6182
180k
        }
6183
124k
        else if ((type->tp_flags & Py_TPFLAGS_HAVE_GC) &&
Line
Count
Source
394
124k
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (6183:18): [True: 124k, False: 0]
6184
124k
                 type->tp_free == NULL &&
  Branch (6184:18): [True: 6.25k, False: 118k]
6185
124k
                 base->tp_free == PyObject_Free) {
  Branch (6185:18): [True: 6.25k, False: 0]
6186
            /* A bit of magic to plug in the correct default
6187
             * tp_free function when a derived class adds gc,
6188
             * didn't define tp_free, and the base uses the
6189
             * default non-gc tp_free.
6190
             */
6191
6.25k
            type->tp_free = PyObject_GC_Del;
6192
6.25k
        }
6193
        /* else they didn't agree about gc, and there isn't something
6194
         * obvious to be done -- the type is on its own.
6195
         */
6196
305k
    }
6197
305k
    return 0;
6198
305k
}
6199
6200
static int add_operators(PyTypeObject *);
6201
static int add_tp_new_wrapper(PyTypeObject *type);
6202
6203
594k
#define COLLECTION_FLAGS (Py_TPFLAGS_SEQUENCE | Py_TPFLAGS_MAPPING)
6204
6205
static int
6206
type_ready_pre_checks(PyTypeObject *type)
6207
114k
{
6208
    /* Consistency checks for PEP 590:
6209
     * - Py_TPFLAGS_METHOD_DESCRIPTOR requires tp_descr_get
6210
     * - Py_TPFLAGS_HAVE_VECTORCALL requires tp_call and
6211
     *   tp_vectorcall_offset > 0
6212
     * To avoid mistakes, we require this before inheriting.
6213
     */
6214
114k
    if (type->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR) {
Line
Count
Source
404
114k
#define Py_TPFLAGS_METHOD_DESCRIPTOR (1UL << 17)
  Branch (6214:9): [True: 410, False: 114k]
6215
410
        _PyObject_ASSERT((PyObject *)type, type->tp_descr_get != NULL);
Line
Count
Source
390
410
    _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
Line
Count
Source
388
410
    _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
Line
Count
Source
377
410
    ((void)0)
6216
410
    }
6217
114k
    if (type->tp_flags & Py_TPFLAGS_HAVE_VECTORCALL) {
Line
Count
Source
382
114k
#define Py_TPFLAGS_HAVE_VECTORCALL (1UL << 11)
  Branch (6217:9): [True: 1.05k, False: 113k]
6218
1.05k
        _PyObject_ASSERT((PyObject *)type, type->tp_vectorcall_offset > 0);
Line
Count
Source
390
1.05k
    _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
Line
Count
Source
388
1.05k
    _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
Line
Count
Source
377
1.05k
    ((void)0)
6219
1.05k
        _PyObject_ASSERT((PyObject *)type, type->tp_call != NULL);
Line
Count
Source
390
1.05k
    _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
Line
Count
Source
388
1.05k
    _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
Line
Count
Source
377
1.05k
    ((void)0)
6220
1.05k
    }
6221
6222
    /* Consistency checks for pattern matching
6223
     * Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING are mutually exclusive */
6224
114k
    _PyObject_ASSERT((PyObject *)type, (type->tp_flags & COLLECTION_FLAGS) != COLLECTION_FLAGS);
Line
Count
Source
390
114k
    _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
Line
Count
Source
388
114k
    _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
Line
Count
Source
377
114k
    ((void)0)
6225
6226
114k
    if (type->tp_name == NULL) {
  Branch (6226:9): [True: 0, False: 114k]
6227
0
        PyErr_Format(PyExc_SystemError,
6228
0
                     "Type does not define the tp_name field.");
6229
0
        return -1;
6230
0
    }
6231
114k
    return 0;
6232
114k
}
6233
6234
6235
static int
6236
type_ready_set_bases(PyTypeObject *type)
6237
114k
{
6238
    /* Initialize tp_base (defaults to BaseObject unless that's us) */
6239
114k
    PyTypeObject *base = type->tp_base;
6240
114k
    if (base == NULL && type != &PyBaseObject_Type) {
  Branch (6240:9): [True: 9.07k, False: 105k]
  Branch (6240:25): [True: 8.97k, False: 104]
6241
8.97k
        base = &PyBaseObject_Type;
6242
8.97k
        if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
Line
Count
Source
375
8.97k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (6242:13): [True: 0, False: 8.97k]
6243
0
            type->tp_base = (PyTypeObject*)Py_NewRef((PyObject*)base);
Line
Count
Source
639
0
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
6244
0
        }
6245
8.97k
        else {
6246
8.97k
            type->tp_base = base;
6247
8.97k
        }
6248
8.97k
    }
6249
114k
    assert(type->tp_base != NULL || type == &PyBaseObject_Type);
6250
6251
    /* Now the only way base can still be NULL is if type is
6252
     * &PyBaseObject_Type. */
6253
6254
    /* Initialize the base class */
6255
114k
    if (base != NULL && !_PyType_IsReady(base)) {
Line
Count
Source
241
114k
#define _PyType_IsReady(type) ((type)->tp_dict != NULL)
  Branch (6255:9): [True: 114k, False: 104]
  Branch (6255:25): [True: 0, False: 114k]
6256
0
        if (PyType_Ready(base) < 0) {
  Branch (6256:13): [True: 0, False: 0]
6257
0
            return -1;
6258
0
        }
6259
0
    }
6260
6261
    /* Initialize ob_type if NULL.      This means extensions that want to be
6262
       compilable separately on Windows can call PyType_Ready() instead of
6263
       initializing the ob_type field of their type objects. */
6264
    /* The test for base != NULL is really unnecessary, since base is only
6265
       NULL when type is &PyBaseObject_Type, and we know its ob_type is
6266
       not NULL (it's initialized to &PyType_Type).      But coverity doesn't
6267
       know that. */
6268
114k
    if (Py_IS_TYPE(type, NULL) && base != NULL) {
Line
Count
Source
155
229k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
114k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
114k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 7.85k, False: 106k]
  Branch (6268:35): [True: 7.85k, False: 0]
6269
7.85k
        Py_SET_TYPE(type, Py_TYPE(base));
Line
Count
Source
171
7.85k
#  define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
Line
Count
Source
109
7.85k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7.85k
#  define _Py_CAST(type, expr) ((type)(expr))
6270
7.85k
    }
6271
6272
    /* Initialize tp_bases */
6273
114k
    PyObject *bases = type->tp_bases;
6274
114k
    if (bases == NULL) {
  Branch (6274:9): [True: 22.4k, False: 92.3k]
6275
22.4k
        PyTypeObject *base = type->tp_base;
6276
22.4k
        if (base == NULL) {
  Branch (6276:13): [True: 104, False: 22.3k]
6277
104
            bases = PyTuple_New(0);
6278
104
        }
6279
22.3k
        else {
6280
22.3k
            bases = PyTuple_Pack(1, base);
6281
22.3k
        }
6282
22.4k
        if (bases == NULL) {
  Branch (6282:13): [True: 0, False: 22.4k]
6283
0
            return -1;
6284
0
        }
6285
22.4k
        type->tp_bases = bases;
6286
22.4k
    }
6287
114k
    return 0;
6288
114k
}
6289
6290
6291
static int
6292
type_ready_set_dict(PyTypeObject *type)
6293
114k
{
6294
114k
    if (type->tp_dict != NULL) {
  Branch (6294:9): [True: 86.7k, False: 28.1k]
6295
86.7k
        return 0;
6296
86.7k
    }
6297
6298
28.1k
    PyObject *dict = PyDict_New();
6299
28.1k
    if (dict == NULL) {
  Branch (6299:9): [True: 0, False: 28.1k]
6300
0
        return -1;
6301
0
    }
6302
28.1k
    type->tp_dict = dict;
6303
28.1k
    return 0;
6304
28.1k
}
6305
6306
6307
/* If the type dictionary doesn't contain a __doc__, set it from
6308
   the tp_doc slot. */
6309
static int
6310
type_dict_set_doc(PyTypeObject *type)
6311
114k
{
6312
114k
    int r = PyDict_Contains(type->tp_dict, &_Py_ID(__doc__));
Line
Count
Source
374
114k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
114k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
114k
    _PyRuntime.global_objects.NAME
6313
114k
    if (r < 0) {
  Branch (6313:9): [True: 0, False: 114k]
6314
0
        return -1;
6315
0
    }
6316
114k
    if (r > 0) {
  Branch (6316:9): [True: 33.1k, False: 81.7k]
6317
33.1k
        return 0;
6318
33.1k
    }
6319
6320
81.7k
    if (type->tp_doc != NULL) {
  Branch (6320:9): [True: 18.5k, False: 63.1k]
6321
18.5k
        const char *doc_str;
6322
18.5k
        doc_str = _PyType_DocWithoutSignature(type->tp_name, type->tp_doc);
6323
18.5k
        PyObject *doc = PyUnicode_FromString(doc_str);
6324
18.5k
        if (doc == NULL) {
  Branch (6324:13): [True: 0, False: 18.5k]
6325
0
            return -1;
6326
0
        }
6327
6328
18.5k
        if (PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), doc) < 0) {
Line
Count
Source
374
18.5k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
18.5k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
18.5k
    _PyRuntime.global_objects.NAME
  Branch (6328:13): [True: 0, False: 18.5k]
6329
0
            Py_DECREF(doc);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
6330
0
            return -1;
6331
0
        }
6332
18.5k
        Py_DECREF(doc);
Line
Count
Source
548
18.5k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
18.5k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
18.5k
#  define _Py_CAST(type, expr) ((type)(expr))
6333
18.5k
    }
6334
63.1k
    else {
6335
63.1k
        if (PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), Py_None) < 0) {
Line
Count
Source
374
63.1k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
63.1k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
63.1k
    _PyRuntime.global_objects.NAME
        if (PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), Py_None) < 0) {
Line
Count
Source
654
63.1k
#define Py_None (&_Py_NoneStruct)
  Branch (6335:13): [True: 0, False: 63.1k]
6336
0
            return -1;
6337
0
        }
6338
63.1k
    }
6339
81.7k
    return 0;
6340
81.7k
}
6341
6342
6343
static int
6344
type_ready_fill_dict(PyTypeObject *type)
6345
114k
{
6346
    /* Add type-specific descriptors to tp_dict */
6347
114k
    if (add_operators(type) < 0) {
  Branch (6347:9): [True: 0, False: 114k]
6348
0
        return -1;
6349
0
    }
6350
114k
    if (type_add_methods(type) < 0) {
  Branch (6350:9): [True: 0, False: 114k]
6351
0
        return -1;
6352
0
    }
6353
114k
    if (type_add_members(type) < 0) {
  Branch (6353:9): [True: 0, False: 114k]
6354
0
        return -1;
6355
0
    }
6356
114k
    if (type_add_getset(type) < 0) {
  Branch (6356:9): [True: 0, False: 114k]
6357
0
        return -1;
6358
0
    }
6359
114k
    if (type_dict_set_doc(type) < 0) {
  Branch (6359:9): [True: 0, False: 114k]
6360
0
        return -1;
6361
0
    }
6362
114k
    return 0;
6363
114k
}
6364
6365
6366
static int
6367
type_ready_mro(PyTypeObject *type)
6368
114k
{
6369
    /* Calculate method resolution order */
6370
114k
    if (mro_internal(type, NULL) < 0) {
  Branch (6370:9): [True: 16, False: 114k]
6371
16
        return -1;
6372
16
    }
6373
114k
    assert(type->tp_mro != NULL);
6374
114k
    assert(PyTuple_Check(type->tp_mro));
6375
6376
    /* All bases of statically allocated type should be statically allocated */
6377
114k
    if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
Line
Count
Source
375
114k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (6377:9): [True: 22.4k, False: 92.3k]
6378
22.4k
        PyObject *mro = type->tp_mro;
6379
22.4k
        Py_ssize_t n = PyTuple_GET_SIZE(mro);
Line
Count
Source
26
22.4k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
22.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
22.4k
#  define _Py_CAST(type, expr) ((type)(expr))
6380
89.4k
        for (Py_ssize_t i = 0; i < n; i++) {
  Branch (6380:32): [True: 67.0k, False: 22.4k]
6381
67.0k
            PyTypeObject *base = _PyType_CAST(PyTuple_GET_ITEM(mro, i));
Line
Count
Source
792
67.0k
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
67.0k
#  define _Py_CAST(type, expr) ((type)(expr))
6382
67.0k
            if (base->tp_flags & Py_TPFLAGS_HEAPTYPE) {
Line
Count
Source
375
67.0k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (6382:17): [True: 0, False: 67.0k]
6383
0
                PyErr_Format(PyExc_TypeError,
6384
0
                             "type '%.100s' is not dynamically allocated but "
6385
0
                             "its base type '%.100s' is dynamically allocated",
6386
0
                             type->tp_name, base->tp_name);
6387
0
                return -1;
6388
0
            }
6389
67.0k
        }
6390
22.4k
    }
6391
114k
    return 0;
6392
114k
}
6393
6394
6395
// For static types, inherit tp_as_xxx structures from the base class
6396
// if it's NULL.
6397
//
6398
// For heap types, tp_as_xxx structures are not NULL: they are set to the
6399
// PyHeapTypeObject.as_xxx fields by type_new_alloc().
6400
static void
6401
type_ready_inherit_as_structs(PyTypeObject *type, PyTypeObject *base)
6402
114k
{
6403
114k
    if (type->tp_as_async == NULL) {
  Branch (6403:9): [True: 21.6k, False: 93.0k]
6404
21.6k
        type->tp_as_async = base->tp_as_async;
6405
21.6k
    }
6406
114k
    if (type->tp_as_number == NULL) {
  Branch (6406:9): [True: 19.7k, False: 94.9k]
6407
19.7k
        type->tp_as_number = base->tp_as_number;
6408
19.7k
    }
6409
114k
    if (type->tp_as_sequence == NULL) {
  Branch (6409:9): [True: 19.9k, False: 94.7k]
6410
19.9k
        type->tp_as_sequence = base->tp_as_sequence;
6411
19.9k
    }
6412
114k
    if (type->tp_as_mapping == NULL) {
  Branch (6412:9): [True: 20.0k, False: 94.6k]
6413
20.0k
        type->tp_as_mapping = base->tp_as_mapping;
6414
20.0k
    }
6415
114k
    if (type->tp_as_buffer == NULL) {
  Branch (6415:9): [True: 21.8k, False: 92.9k]
6416
21.8k
        type->tp_as_buffer = base->tp_as_buffer;
6417
21.8k
    }
6418
114k
}
6419
6420
static void
6421
305k
inherit_patma_flags(PyTypeObject *type, PyTypeObject *base) {
6422
305k
    if ((type->tp_flags & COLLECTION_FLAGS) == 0) {
Line
Count
Source
6203
305k
#define COLLECTION_FLAGS (Py_TPFLAGS_SEQUENCE | Py_TPFLAGS_MAPPING)
Line
Count
Source
362
305k
#define Py_TPFLAGS_SEQUENCE (1 << 5)
#define COLLECTION_FLAGS (Py_TPFLAGS_SEQUENCE | Py_TPFLAGS_MAPPING)
Line
Count
Source
364
305k
#define Py_TPFLAGS_MAPPING (1 << 6)
  Branch (6422:9): [True: 289k, False: 15.8k]
6423
289k
        type->tp_flags |= base->tp_flags & COLLECTION_FLAGS;
Line
Count
Source
6203
289k
#define COLLECTION_FLAGS (Py_TPFLAGS_SEQUENCE | Py_TPFLAGS_MAPPING)
Line
Count
Source
362
289k
#define Py_TPFLAGS_SEQUENCE (1 << 5)
#define COLLECTION_FLAGS (Py_TPFLAGS_SEQUENCE | Py_TPFLAGS_MAPPING)
Line
Count
Source
364
289k
#define Py_TPFLAGS_MAPPING (1 << 6)
6424
289k
    }
6425
305k
}
6426
6427
static int
6428
type_ready_inherit(PyTypeObject *type)
6429
114k
{
6430
    /* Inherit special flags from dominant base */
6431
114k
    PyTypeObject *base = type->tp_base;
6432
114k
    if (base != NULL) {
  Branch (6432:9): [True: 114k, False: 104]
6433
114k
        inherit_special(type, base);
6434
114k
    }
6435
6436
    // Inherit slots
6437
114k
    PyObject *mro = type->tp_mro;
6438
114k
    Py_ssize_t n = PyTuple_GET_SIZE(type->tp_mro);
Line
Count
Source
26
114k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
114k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
114k
#  define _Py_CAST(type, expr) ((type)(expr))
6439
419k
    for (Py_ssize_t i = 1; i < n; i++) {
  Branch (6439:28): [True: 305k, False: 114k]
6440
305k
        PyObject *b = PyTuple_GET_ITEM(mro, i);
Line
Count
Source
28
305k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
305k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
305k
#  define _Py_CAST(type, expr) ((type)(expr))
6441
305k
        if (PyType_Check(b)) {
Line
Count
Source
788
305k
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
305k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
305k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (788:28): [True: 305k, False: 0]
6442
305k
            if (inherit_slots(type, (PyTypeObject *)b) < 0) {
  Branch (6442:17): [True: 0, False: 305k]
6443
0
                return -1;
6444
0
            }
6445
305k
            inherit_patma_flags(type, (PyTypeObject *)b);
6446
305k
        }
6447
305k
    }
6448
6449
114k
    if (base != NULL) {
  Branch (6449:9): [True: 114k, False: 104]
6450
114k
        type_ready_inherit_as_structs(type, base);
6451
114k
    }
6452
6453
    /* Sanity check for tp_free. */
6454
114k
    if (_PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) &&
Line
Count
Source
222
229k
#define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
Line
Count
Source
394
114k
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (222:26): [True: 110k, False: 3.94k]
    if (_PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) &&
Line
Count
Source
378
110k
#define Py_TPFLAGS_BASETYPE (1UL << 10)
  Branch (6454:32): [True: 98.7k, False: 12.1k]
6455
114k
        (type->tp_free == NULL || type->tp_free == PyObject_Del))
Line
Count
Source
111
98.7k
#define PyObject_Del            PyObject_Free
  Branch (6455:10): [True: 0, False: 98.7k]
  Branch (6455:35): [True: 0, False: 98.7k]
6456
0
    {
6457
        /* This base class needs to call tp_free, but doesn't have
6458
         * one, or its tp_free is for non-gc'ed objects.
6459
         */
6460
0
        PyErr_Format(PyExc_TypeError, "type '%.100s' participates in "
6461
0
                     "gc and is a base type but has inappropriate "
6462
0
                     "tp_free slot",
6463
0
                     type->tp_name);
6464
0
        return -1;
6465
0
    }
6466
6467
114k
    return 0;
6468
114k
}
6469
6470
6471
/* Hack for tp_hash and __hash__.
6472
   If after all that, tp_hash is still NULL, and __hash__ is not in
6473
   tp_dict, set tp_hash to PyObject_HashNotImplemented and
6474
   tp_dict['__hash__'] equal to None.
6475
   This signals that __hash__ is not inherited. */
6476
static int
6477
type_ready_set_hash(PyTypeObject *type)
6478
114k
{
6479
114k
    if (type->tp_hash != NULL) {
  Branch (6479:9): [True: 97.7k, False: 17.0k]
6480
97.7k
        return 0;
6481
97.7k
    }
6482
6483
17.0k
    int r = PyDict_Contains(type->tp_dict, &_Py_ID(__hash__));
Line
Count
Source
374
17.0k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
17.0k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
17.0k
    _PyRuntime.global_objects.NAME
6484
17.0k
    if (r < 0) {
  Branch (6484:9): [True: 0, False: 17.0k]
6485
0
        return -1;
6486
0
    }
6487
17.0k
    if (r > 0) {
  Branch (6487:9): [True: 14.8k, False: 2.21k]
6488
14.8k
        return 0;
6489
14.8k
    }
6490
6491
2.21k
    if (PyDict_SetItem(type->tp_dict, &_Py_ID(__hash__), Py_None) < 0) {
Line
Count
Source
374
2.21k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
2.21k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
2.21k
    _PyRuntime.global_objects.NAME
    if (PyDict_SetItem(type->tp_dict, &_Py_ID(__hash__), Py_None) < 0) {
Line
Count
Source
654
2.21k
#define Py_None (&_Py_NoneStruct)
  Branch (6491:9): [True: 0, False: 2.21k]
6492
0
        return -1;
6493
0
    }
6494
2.21k
    type->tp_hash = PyObject_HashNotImplemented;
6495
2.21k
    return 0;
6496
2.21k
}
6497
6498
6499
/* Link into each base class's list of subclasses */
6500
static int
6501
type_ready_add_subclasses(PyTypeObject *type)
6502
114k
{
6503
114k
    PyObject *bases = type->tp_bases;
6504
114k
    Py_ssize_t nbase = PyTuple_GET_SIZE(bases);
Line
Count
Source
26
114k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
114k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
114k
#  define _Py_CAST(type, expr) ((type)(expr))
6505
244k
    for (Py_ssize_t i = 0; i < nbase; i++) {
  Branch (6505:28): [True: 129k, False: 114k]
6506
129k
        PyObject *b = PyTuple_GET_ITEM(bases, i);
Line
Count
Source
28
129k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
129k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
129k
#  define _Py_CAST(type, expr) ((type)(expr))
6507
129k
        if (PyType_Check(b) && add_subclass((PyTypeObject *)b, type) < 0) {
Line
Count
Source
788
258k
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
129k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
129k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (788:28): [True: 129k, False: 0]
  Branch (6507:32): [True: 0, False: 129k]
6508
0
            return -1;
6509
0
        }
6510
129k
    }
6511
114k
    return 0;
6512
114k
}
6513
6514
6515
// Set tp_new and the "__new__" key in the type dictionary.
6516
// Use the Py_TPFLAGS_DISALLOW_INSTANTIATION flag.
6517
static int
6518
type_ready_set_new(PyTypeObject *type)
6519
114k
{
6520
114k
    PyTypeObject *base = type->tp_base;
6521
    /* The condition below could use some explanation.
6522
6523
       It appears that tp_new is not inherited for static types whose base
6524
       class is 'object'; this seems to be a precaution so that old extension
6525
       types don't suddenly become callable (object.__new__ wouldn't insure the
6526
       invariants that the extension type's own factory function ensures).
6527
6528
       Heap types, of course, are under our control, so they do inherit tp_new;
6529
       static extension types that specify some other built-in type as the
6530
       default also inherit object.__new__. */
6531
114k
    if (type->tp_new == NULL
  Branch (6531:9): [True: 97.5k, False: 17.3k]
6532
114k
        && base == &PyBaseObject_Type
  Branch (6532:12): [True: 39.5k, False: 57.9k]
6533
114k
        && !(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
Line
Count
Source
375
39.5k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (6533:12): [True: 6.54k, False: 33.0k]
6534
6.54k
    {
6535
6.54k
        type->tp_flags |= Py_TPFLAGS_DISALLOW_INSTANTIATION;
Line
Count
Source
369
6.54k
#define Py_TPFLAGS_DISALLOW_INSTANTIATION (1UL << 7)
6536
6.54k
    }
6537
6538
114k
    if (!(type->tp_flags & Py_TPFLAGS_DISALLOW_INSTANTIATION)) {
Line
Count
Source
369
114k
#define Py_TPFLAGS_DISALLOW_INSTANTIATION (1UL << 7)
  Branch (6538:9): [True: 106k, False: 8.26k]
6539
106k
        if (type->tp_new != NULL) {
  Branch (6539:13): [True: 17.0k, False: 89.4k]
6540
            // If "__new__" key does not exists in the type dictionary,
6541
            // set it to tp_new_wrapper().
6542
17.0k
            if (add_tp_new_wrapper(type) < 0) {
  Branch (6542:17): [True: 0, False: 17.0k]
6543
0
                return -1;
6544
0
            }
6545
17.0k
        }
6546
89.4k
        else {
6547
            // tp_new is NULL: inherit tp_new from base
6548
89.4k
            type->tp_new = base->tp_new;
6549
89.4k
        }
6550
106k
    }
6551
8.26k
    else {
6552
        // Py_TPFLAGS_DISALLOW_INSTANTIATION sets tp_new to NULL
6553
8.26k
        type->tp_new = NULL;
6554
8.26k
    }
6555
114k
    return 0;
6556
114k
}
6557
6558
6559
static int
6560
type_ready_post_checks(PyTypeObject *type)
6561
114k
{
6562
    // bpo-44263: tp_traverse is required if Py_TPFLAGS_HAVE_GC is set.
6563
    // Note: tp_clear is optional.
6564
114k
    if (type->tp_flags & Py_TPFLAGS_HAVE_GC
Line
Count
Source
394
229k
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
  Branch (6564:9): [True: 110k, False: 3.94k]
6565
114k
        && type->tp_traverse == NULL)
  Branch (6565:12): [True: 0, False: 110k]
6566
0
    {
6567
0
        PyErr_Format(PyExc_SystemError,
6568
0
                     "type %s has the Py_TPFLAGS_HAVE_GC flag "
6569
0
                     "but has no traverse function",
6570
0
                     type->tp_name);
6571
0
        return -1;
6572
0
    }
6573
114k
    return 0;
6574
114k
}
6575
6576
6577
static int
6578
type_ready(PyTypeObject *type)
6579
114k
{
6580
114k
    if (type_ready_pre_checks(type) < 0) {
  Branch (6580:9): [True: 0, False: 114k]
6581
0
        return -1;
6582
0
    }
6583
6584
#ifdef Py_TRACE_REFS
6585
    /* PyType_Ready is the closest thing we have to a choke point
6586
     * for type objects, so is the best place I can think of to try
6587
     * to get type objects into the doubly-linked list of all objects.
6588
     * Still, not all type objects go through PyType_Ready.
6589
     */
6590
    _Py_AddToAllObjects((PyObject *)type, 0);
6591
#endif
6592
6593
    /* Initialize tp_dict: _PyType_IsReady() tests if tp_dict != NULL */
6594
114k
    if (type_ready_set_dict(type) < 0) {
  Branch (6594:9): [True: 0, False: 114k]
6595
0
        return -1;
6596
0
    }
6597
114k
    if (type_ready_set_bases(type) < 0) {
  Branch (6597:9): [True: 0, False: 114k]
6598
0
        return -1;
6599
0
    }
6600
114k
    if (type_ready_mro(type) < 0) {
  Branch (6600:9): [True: 16, False: 114k]
6601
16
        return -1;
6602
16
    }
6603
114k
    if (type_ready_set_new(type) < 0) {
  Branch (6603:9): [True: 0, False: 114k]
6604
0
        return -1;
6605
0
    }
6606
114k
    if (type_ready_fill_dict(type) < 0) {
  Branch (6606:9): [True: 0, False: 114k]
6607
0
        return -1;
6608
0
    }
6609
114k
    if (type_ready_inherit(type) < 0) {
  Branch (6609:9): [True: 0, False: 114k]
6610
0
        return -1;
6611
0
    }
6612
114k
    if (type_ready_set_hash(type) < 0) {
  Branch (6612:9): [True: 0, False: 114k]
6613
0
        return -1;
6614
0
    }
6615
114k
    if (type_ready_add_subclasses(type) < 0) {
  Branch (6615:9): [True: 0, False: 114k]
6616
0
        return -1;
6617
0
    }
6618
114k
    if (type_ready_post_checks(type) < 0) {
  Branch (6618:9): [True: 0, False: 114k]
6619
0
        return -1;
6620
0
    }
6621
114k
    return 0;
6622
114k
}
6623
6624
6625
int
6626
PyType_Ready(PyTypeObject *type)
6627
121k
{
6628
121k
    if (type->tp_flags & Py_TPFLAGS_READY) {
Line
Count
Source
388
121k
#define Py_TPFLAGS_READY (1UL << 12)
  Branch (6628:9): [True: 6.56k, False: 114k]
6629
6.56k
        assert(_PyType_CheckConsistency(type));
6630
6.56k
        return 0;
6631
6.56k
    }
6632
114k
    _PyObject_ASSERT((PyObject *)type,
Line
Count
Source
390
114k
    _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
Line
Count
Source
388
114k
    _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
Line
Count
Source
377
114k
    ((void)0)
6633
114k
                     (type->tp_flags & Py_TPFLAGS_READYING) == 0);
6634
6635
114k
    type->tp_flags |= Py_TPFLAGS_READYING;
Line
Count
Source
391
114k
#define Py_TPFLAGS_READYING (1UL << 13)
6636
6637
    /* Historically, all static types were immutable. See bpo-43908 */
6638
114k
    if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
Line
Count
Source
375
114k
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
  Branch (6638:9): [True: 22.4k, False: 92.3k]
6639
22.4k
        type->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE;
Line
Count
Source
372
22.4k
#define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
6640
22.4k
    }
6641
6642
114k
    if (type_ready(type) < 0) {
  Branch (6642:9): [True: 16, False: 114k]
6643
16
        type->tp_flags &= ~Py_TPFLAGS_READYING;
Line
Count
Source
391
16
#define Py_TPFLAGS_READYING (1UL << 13)
6644
16
        return -1;
6645
16
    }
6646
6647
    /* All done -- set the ready flag */
6648
114k
    type->tp_flags = (type->tp_flags & ~Py_TPFLAGS_READYING) | Py_TPFLAGS_READY;
Line
Count
Source
391
114k
#define Py_TPFLAGS_READYING (1UL << 13)
    type->tp_flags = (type->tp_flags & ~Py_TPFLAGS_READYING) | Py_TPFLAGS_READY;
Line
Count
Source
388
114k
#define Py_TPFLAGS_READY (1UL << 12)
6649
114k
    assert(_PyType_CheckConsistency(type));
6650
114k
    return 0;
6651
114k
}
6652
6653
6654
static int
6655
add_subclass(PyTypeObject *base, PyTypeObject *type)
6656
129k
{
6657
129k
    PyObject *key = PyLong_FromVoidPtr((void *) type);
6658
129k
    if (key == NULL)
  Branch (6658:9): [True: 0, False: 129k]
6659
0
        return -1;
6660
6661
129k
    PyObject *ref = PyWeakref_NewRef((PyObject *)type, NULL);
6662
129k
    if (ref == NULL) {
  Branch (6662:9): [True: 0, False: 129k]
6663
0
        Py_DECREF(key);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
6664
0
        return -1;
6665
0
    }
6666
6667
    // Only get tp_subclasses after creating the key and value.
6668
    // PyWeakref_NewRef() can trigger a garbage collection which can execute
6669
    // arbitrary Python code and so modify base->tp_subclasses.
6670
129k
    PyObject *subclasses = base->tp_subclasses;
6671
129k
    if (subclasses == NULL) {
  Branch (6671:9): [True: 16.2k, False: 113k]
6672
16.2k
        base->tp_subclasses = subclasses = PyDict_New();
6673
16.2k
        if (subclasses == NULL) {
  Branch (6673:13): [True: 0, False: 16.2k]
6674
0
            Py_DECREF(key);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
6675
0
            Py_DECREF(ref);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
6676
0
            return -1;
6677
0
        }
6678
16.2k
    }
6679
129k
    assert(PyDict_CheckExact(subclasses));
6680
6681
129k
    int result = PyDict_SetItem(subclasses, key, ref);
6682
129k
    Py_DECREF(ref);
Line
Count
Source
548
129k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
129k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
129k
#  define _Py_CAST(type, expr) ((type)(expr))
6683
129k
    Py_DECREF(key);
Line
Count
Source
548
129k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
129k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
129k
#  define _Py_CAST(type, expr) ((type)(expr))
6684
129k
    return result;
6685
129k
}
6686
6687
static int
6688
add_all_subclasses(PyTypeObject *type, PyObject *bases)
6689
45
{
6690
45
    Py_ssize_t n = PyTuple_GET_SIZE(bases);
Line
Count
Source
26
45
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
45
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
45
#  define _Py_CAST(type, expr) ((type)(expr))
6691
45
    int res = 0;
6692
96
    for (Py_ssize_t i = 0; i < n; i++) {
  Branch (6692:28): [True: 51, False: 45]
6693
51
        PyObject *obj = PyTuple_GET_ITEM(bases, i);
Line
Count
Source
28
51
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
51
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
51
#  define _Py_CAST(type, expr) ((type)(expr))
6694
        // bases tuple must only contain types
6695
51
        PyTypeObject *base = _PyType_CAST(obj);
Line
Count
Source
792
51
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
51
#  define _Py_CAST(type, expr) ((type)(expr))
6696
51
        if (add_subclass(base, type) < 0) {
  Branch (6696:13): [True: 0, False: 51]
6697
0
            res = -1;
6698
0
        }
6699
51
    }
6700
45
    return res;
6701
45
}
6702
6703
static void
6704
remove_subclass(PyTypeObject *base, PyTypeObject *type)
6705
126k
{
6706
126k
    PyObject *subclasses = base->tp_subclasses;  // borrowed ref
6707
126k
    if (subclasses == NULL) {
  Branch (6707:9): [True: 12, False: 126k]
6708
12
        return;
6709
12
    }
6710
126k
    assert(PyDict_CheckExact(subclasses));
6711
6712
126k
    PyObject *key = PyLong_FromVoidPtr((void *) type);
6713
126k
    if (key == NULL || PyDict_DelItem(subclasses, key)) {
  Branch (6713:9): [True: 0, False: 126k]
  Branch (6713:24): [True: 31, False: 126k]
6714
        /* This can happen if the type initialization errored out before
6715
           the base subclasses were updated (e.g. a non-str __qualname__
6716
           was passed in the type dict). */
6717
31
        PyErr_Clear();
6718
31
    }
6719
126k
    Py_XDECREF(key);
Line
Count
Source
613
126k
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
126k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
126k
#  define _Py_CAST(type, expr) ((type)(expr))
6720
6721
126k
    if (PyDict_Size(subclasses) == 0) {
  Branch (6721:9): [True: 15.7k, False: 110k]
6722
        // Delete the dictionary to save memory. _PyStaticType_Dealloc()
6723
        // callers also test if tp_subclasses is NULL to check if a static type
6724
        // has no subclass.
6725
15.7k
        Py_CLEAR(base->tp_subclasses);
Line
Count
Source
587
15.7k
    do {                                        \
588
15.7k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
15.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
15.7k
#  define _Py_CAST(type, expr) ((type)(expr))
589
15.7k
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 15.7k, False: 0]
590
15.7k
            (op) = NULL;                        \
591
15.7k
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
15.7k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
15.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
15.7k
#  define _Py_CAST(type, expr) ((type)(expr))
592
15.7k
        }                                       \
593
15.7k
    } while (0)
  Branch (593:14): [Folded - Ignored]
6726
15.7k
    }
6727
126k
}
6728
6729
static void
6730
remove_all_subclasses(PyTypeObject *type, PyObject *bases)
6731
111k
{
6732
111k
    assert(bases != NULL);
6733
    // remove_subclass() can clear the current exception
6734
111k
    assert(!PyErr_Occurred());
6735
6736
237k
    for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(bases); i++) {
Line
Count
Source
26
237k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
237k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
237k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (6736:28): [True: 126k, False: 111k]
6737
126k
        PyObject *base = PyTuple_GET_ITEM(bases, i);
Line
Count
Source
28
126k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
126k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
126k
#  define _Py_CAST(type, expr) ((type)(expr))
6738
126k
        if (PyType_Check(base)) {
Line
Count
Source
788
126k
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
126k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
126k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (788:28): [True: 126k, False: 0]
6739
126k
            remove_subclass((PyTypeObject*) base, type);
6740
126k
        }
6741
126k
    }
6742
111k
    assert(!PyErr_Occurred());
6743
111k
}
6744
6745
static int
6746
check_num_args(PyObject *ob, int n)
6747
1.57M
{
6748
1.57M
    if (!PyTuple_CheckExact(ob)) {
Line
Count
Source
28
1.57M
#define PyTuple_CheckExact(op) Py_IS_TYPE((op), &PyTuple_Type)
Line
Count
Source
155
1.57M
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
1.57M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.57M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (6748:9): [True: 0, False: 1.57M]
6749
0
        PyErr_SetString(PyExc_SystemError,
6750
0
            "PyArg_UnpackTuple() argument list is not a tuple");
6751
0
        return 0;
6752
0
    }
6753
1.57M
    if (n == PyTuple_GET_SIZE(ob))
Line
Count
Source
26
1.57M
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
1.57M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.57M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (6753:9): [True: 1.57M, False: 35]
6754
1.57M
        return 1;
6755
35
    PyErr_Format(
6756
35
        PyExc_TypeError,
6757
35
        "expected %d argument%s, got %zd", n, n == 1 ? "" : "s", PyTuple_GET_SIZE(ob));
Line
Count
Source
26
35
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
35
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
35
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (6757:47): [True: 34, False: 1]
6758
35
    return 0;
6759
1.57M
}
6760
6761
/* Generic wrappers for overloadable 'operators' such as __getitem__ */
6762
6763
/* There's a wrapper *function* for each distinct function typedef used
6764
   for type object slots (e.g. binaryfunc, ternaryfunc, etc.).  There's a
6765
   wrapper *table* for each distinct operation (e.g. __len__, __add__).
6766
   Most tables have only one entry; the tables for binary operators have two
6767
   entries, one regular and one with reversed arguments. */
6768
6769
static PyObject *
6770
wrap_lenfunc(PyObject *self, PyObject *args, void *wrapped)
6771
4.42k
{
6772
4.42k
    lenfunc func = (lenfunc)wrapped;
6773
4.42k
    Py_ssize_t res;
6774
6775
4.42k
    if (!check_num_args(args, 0))
  Branch (6775:9): [True: 0, False: 4.42k]
6776
0
        return NULL;
6777
4.42k
    res = (*func)(self);
6778
4.42k
    if (res == -1 && PyErr_Occurred())
  Branch (6778:9): [True: 0, False: 4.42k]
  Branch (6778:22): [True: 0, False: 0]
6779
0
        return NULL;
6780
4.42k
    return PyLong_FromSsize_t(res);
6781
4.42k
}
6782
6783
static PyObject *
6784
wrap_inquirypred(PyObject *self, PyObject *args, void *wrapped)
6785
2
{
6786
2
    inquiry func = (inquiry)wrapped;
6787
2
    int res;
6788
6789
2
    if (!check_num_args(args, 0))
  Branch (6789:9): [True: 0, False: 2]
6790
0
        return NULL;
6791
2
    res = (*func)(self);
6792
2
    if (res == -1 && PyErr_Occurred())
  Branch (6792:9): [True: 0, False: 2]
  Branch (6792:22): [True: 0, False: 0]
6793
0
        return NULL;
6794
2
    return PyBool_FromLong((long)res);
6795
2
}
6796
6797
static PyObject *
6798
wrap_binaryfunc(PyObject *self, PyObject *args, void *wrapped)
6799
497k
{
6800
497k
    binaryfunc func = (binaryfunc)wrapped;
6801
497k
    PyObject *other;
6802
6803
497k
    if (!check_num_args(args, 1))
  Branch (6803:9): [True: 14, False: 497k]
6804
14
        return NULL;
6805
497k
    other = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
497k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
497k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
497k
#  define _Py_CAST(type, expr) ((type)(expr))
6806
497k
    return (*func)(self, other);
6807
497k
}
6808
6809
static PyObject *
6810
wrap_binaryfunc_l(PyObject *self, PyObject *args, void *wrapped)
6811
45.7k
{
6812
45.7k
    binaryfunc func = (binaryfunc)wrapped;
6813
45.7k
    PyObject *other;
6814
6815
45.7k
    if (!check_num_args(args, 1))
  Branch (6815:9): [True: 1, False: 45.7k]
6816
1
        return NULL;
6817
45.7k
    other = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
45.7k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
45.7k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
45.7k
#  define _Py_CAST(type, expr) ((type)(expr))
6818
45.7k
    return (*func)(self, other);
6819
45.7k
}
6820
6821
static PyObject *
6822
wrap_binaryfunc_r(PyObject *self, PyObject *args, void *wrapped)
6823
30
{
6824
30
    binaryfunc func = (binaryfunc)wrapped;
6825
30
    PyObject *other;
6826
6827
30
    if (!check_num_args(args, 1))
  Branch (6827:9): [True: 0, False: 30]
6828
0
        return NULL;
6829
30
    other = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
30
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
30
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
30
#  define _Py_CAST(type, expr) ((type)(expr))
6830
30
    return (*func)(other, self);
6831
30
}
6832
6833
static PyObject *
6834
wrap_ternaryfunc(PyObject *self, PyObject *args, void *wrapped)
6835
8
{
6836
8
    ternaryfunc func = (ternaryfunc)wrapped;
6837
8
    PyObject *other;
6838
8
    PyObject *third = Py_None;
Line
Count
Source
654
8
#define Py_None (&_Py_NoneStruct)
6839
6840
    /* Note: This wrapper only works for __pow__() */
6841
6842
8
    if (!PyArg_UnpackTuple(args, "", 1, 2, &other, &third))
  Branch (6842:9): [True: 0, False: 8]
6843
0
        return NULL;
6844
8
    return (*func)(self, other, third);
6845
8
}
6846
6847
static PyObject *
6848
wrap_ternaryfunc_r(PyObject *self, PyObject *args, void *wrapped)
6849
1
{
6850
1
    ternaryfunc func = (ternaryfunc)wrapped;
6851
1
    PyObject *other;
6852
1
    PyObject *third = Py_None;
Line
Count
Source
654
1
#define Py_None (&_Py_NoneStruct)
6853
6854
    /* Note: This wrapper only works for __pow__() */
6855
6856
1
    if (!PyArg_UnpackTuple(args, "", 1, 2, &other, &third))
  Branch (6856:9): [True: 0, False: 1]
6857
0
        return NULL;
6858
1
    return (*func)(other, self, third);
6859
1
}
6860
6861
static PyObject *
6862
wrap_unaryfunc(PyObject *self, PyObject *args, void *wrapped)
6863
47.4k
{
6864
47.4k
    unaryfunc func = (unaryfunc)wrapped;
6865
6866
47.4k
    if (!check_num_args(args, 0))
  Branch (6866:9): [True: 1, False: 47.4k]
6867
1
        return NULL;
6868
47.4k
    return (*func)(self);
6869
47.4k
}
6870
6871
static PyObject *
6872
wrap_indexargfunc(PyObject *self, PyObject *args, void *wrapped)
6873
66
{
6874
66
    ssizeargfunc func = (ssizeargfunc)wrapped;
6875
66
    PyObject* o;
6876
66
    Py_ssize_t i;
6877
6878
66
    if (!PyArg_UnpackTuple(args, "", 1, 1, &o))
  Branch (6878:9): [True: 1, False: 65]
6879
1
        return NULL;
6880
65
    i = PyNumber_AsSsize_t(o, PyExc_OverflowError);
6881
65
    if (i == -1 && PyErr_Occurred())
  Branch (6881:9): [True: 28, False: 37]
  Branch (6881:20): [True: 27, False: 1]
6882
27
        return NULL;
6883
38
    return (*func)(self, i);
6884
65
}
6885
6886
static Py_ssize_t
6887
getindex(PyObject *self, PyObject *arg)
6888
4
{
6889
4
    Py_ssize_t i;
6890
6891
4
    i = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
6892
4
    if (i == -1 && PyErr_Occurred())
  Branch (6892:9): [True: 1, False: 3]
  Branch (6892:20): [True: 0, False: 1]
6893
0
        return -1;
6894
4
    if (i < 0) {
  Branch (6894:9): [True: 2, False: 2]
6895
2
        PySequenceMethods *sq = Py_TYPE(self)->tp_as_sequence;
Line
Count
Source
138
2
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
6896
2
        if (sq && sq->sq_length) {
  Branch (6896:13): [True: 2, False: 0]
  Branch (6896:19): [True: 2, False: 0]
6897
2
            Py_ssize_t n = (*sq->sq_length)(self);
6898
2
            if (n < 0) {
  Branch (6898:17): [True: 0, False: 2]
6899
0
                assert(PyErr_Occurred());
6900
0
                return -1;
6901
0
            }
6902
2
            i += n;
6903
2
        }
6904
2
    }
6905
4
    return i;
6906
4
}
6907
6908
static PyObject *
6909
wrap_sq_item(PyObject *self, PyObject *args, void *wrapped)
6910
2
{
6911
2
    ssizeargfunc func = (ssizeargfunc)wrapped;
6912
2
    PyObject *arg;
6913
2
    Py_ssize_t i;
6914
6915
2
    if (PyTuple_GET_SIZE(args) == 1) {
Line
Count
Source
26
2
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (6915:9): [True: 2, False: 0]
6916
2
        arg = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
2
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
2
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
6917
2
        i = getindex(self, arg);
6918
2
        if (i == -1 && PyErr_Occurred())
  Branch (6918:13): [True: 1, False: 1]
  Branch (6918:24): [True: 0, False: 1]
6919
0
            return NULL;
6920
2
        return (*func)(self, i);
6921
2
    }
6922
0
    check_num_args(args, 1);
6923
0
    assert(PyErr_Occurred());
6924
0
    return NULL;
6925
2
}
6926
6927
static PyObject *
6928
wrap_sq_setitem(PyObject *self, PyObject *args, void *wrapped)
6929
0
{
6930
0
    ssizeobjargproc func = (ssizeobjargproc)wrapped;
6931
0
    Py_ssize_t i;
6932
0
    int res;
6933
0
    PyObject *arg, *value;
6934
6935
0
    if (!PyArg_UnpackTuple(args, "", 2, 2, &arg, &value))
  Branch (6935:9): [True: 0, False: 0]
6936
0
        return NULL;
6937
0
    i = getindex(self, arg);
6938
0
    if (i == -1 && PyErr_Occurred())
  Branch (6938:9): [True: 0, False: 0]
  Branch (6938:20): [True: 0, False: 0]
6939
0
        return NULL;
6940
0
    res = (*func)(self, i, value);
6941
0
    if (res == -1 && PyErr_Occurred())
  Branch (6941:9): [True: 0, False: 0]
  Branch (6941:22): [True: 0, False: 0]
6942
0
        return NULL;
6943
0
    Py_RETURN_NONE;
Line
Count
Source
661
0
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
0
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
6944
0
}
6945
6946
static PyObject *
6947
wrap_sq_delitem(PyObject *self, PyObject *args, void *wrapped)
6948
2
{
6949
2
    ssizeobjargproc func = (ssizeobjargproc)wrapped;
6950
2
    Py_ssize_t i;
6951
2
    int res;
6952
2
    PyObject *arg;
6953
6954
2
    if (!check_num_args(args, 1))
  Branch (6954:9): [True: 0, False: 2]
6955
0
        return NULL;
6956
2
    arg = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
2
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
2
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
6957
2
    i = getindex(self, arg);
6958
2
    if (i == -1 && PyErr_Occurred())
  Branch (6958:9): [True: 1, False: 1]
  Branch (6958:20): [True: 0, False: 1]
6959
0
        return NULL;
6960
2
    res = (*func)(self, i, NULL);
6961
2
    if (res == -1 && PyErr_Occurred())
  Branch (6961:9): [True: 2, False: 0]
  Branch (6961:22): [True: 2, False: 0]
6962
2
        return NULL;
6963
2
    Py_RETURN_NONE;
Line
Count
Source
661
0
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
0
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
6964
2
}
6965
6966
/* XXX objobjproc is a misnomer; should be objargpred */
6967
static PyObject *
6968
wrap_objobjproc(PyObject *self, PyObject *args, void *wrapped)
6969
68
{
6970
68
    objobjproc func = (objobjproc)wrapped;
6971
68
    int res;
6972
68
    PyObject *value;
6973
6974
68
    if (!check_num_args(args, 1))
  Branch (6974:9): [True: 4, False: 64]
6975
4
        return NULL;
6976
64
    value = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
64
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
64
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
64
#  define _Py_CAST(type, expr) ((type)(expr))
6977
64
    res = (*func)(self, value);
6978
64
    if (res == -1 && PyErr_Occurred())
  Branch (6978:9): [True: 6, False: 58]
  Branch (6978:22): [True: 6, False: 0]
6979
6
        return NULL;
6980
58
    else
6981
58
        return PyBool_FromLong(res);
6982
64
}
6983
6984
static PyObject *
6985
wrap_objobjargproc(PyObject *self, PyObject *args, void *wrapped)
6986
117k
{
6987
117k
    objobjargproc func = (objobjargproc)wrapped;
6988
117k
    int res;
6989
117k
    PyObject *key, *value;
6990
6991
117k
    if (!PyArg_UnpackTuple(args, "", 2, 2, &key, &value))
  Branch (6991:9): [True: 29, False: 117k]
6992
29
        return NULL;
6993
117k
    res = (*func)(self, key, value);
6994
117k
    if (res == -1 && PyErr_Occurred())
  Branch (6994:9): [True: 450, False: 117k]
  Branch (6994:22): [True: 450, False: 0]
6995
450
        return NULL;
6996
117k
    Py_RETURN_NONE;
Line
Count
Source
661
117k
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
117k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
6997
117k
}
6998
6999
static PyObject *
7000
wrap_delitem(PyObject *self, PyObject *args, void *wrapped)
7001
21.7k
{
7002
21.7k
    objobjargproc func = (objobjargproc)wrapped;
7003
21.7k
    int res;
7004
21.7k
    PyObject *key;
7005
7006
21.7k
    if (!check_num_args(args, 1))
  Branch (7006:9): [True: 14, False: 21.6k]
7007
14
        return NULL;
7008
21.6k
    key = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
21.6k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
21.6k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
21.6k
#  define _Py_CAST(type, expr) ((type)(expr))
7009
21.6k
    res = (*func)(self, key, NULL);
7010
21.6k
    if (res == -1 && PyErr_Occurred())
  Branch (7010:9): [True: 50, False: 21.6k]
  Branch (7010:22): [True: 50, False: 0]
7011
50
        return NULL;
7012
21.6k
    Py_RETURN_NONE;
Line
Count
Source
661
21.6k
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
21.6k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
21.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21.6k
#  define _Py_CAST(type, expr) ((type)(expr))
7013
21.6k
}
7014
7015
/* Helper to check for object.__setattr__ or __delattr__ applied to a type.
7016
   This is called the Carlo Verre hack after its discoverer.  See
7017
   https://mail.python.org/pipermail/python-dev/2003-April/034535.html
7018
   */
7019
static int
7020
hackcheck(PyObject *self, setattrofunc func, const char *what)
7021
463k
{
7022
463k
    PyTypeObject *type = Py_TYPE(self);
Line
Count
Source
138
463k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
463k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
463k
#  define _Py_CAST(type, expr) ((type)(expr))
7023
463k
    PyObject *mro = type->tp_mro;
7024
463k
    if (!mro) {
  Branch (7024:9): [True: 0, False: 463k]
7025
        /* Probably ok not to check the call in this case. */
7026
0
        return 1;
7027
0
    }
7028
463k
    assert(PyTuple_Check(mro));
7029
7030
    /* Find the (base) type that defined the type's slot function. */
7031
463k
    PyTypeObject *defining_type = type;
7032
463k
    Py_ssize_t i;
7033
2.44M
    for (i = PyTuple_GET_SIZE(mro) - 1; i >= 0; i--) {
Line
Count
Source
26
463k
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
463k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
463k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7033:41): [True: 1.98M, False: 463k]
7034
1.98M
        PyTypeObject *base = _PyType_CAST(PyTuple_GET_ITEM(mro, i));
Line
Count
Source
792
1.98M
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
1.98M
#  define _Py_CAST(type, expr) ((type)(expr))
7035
1.98M
        if (base->tp_setattro == slot_tp_setattro) {
  Branch (7035:13): [True: 967k, False: 1.01M]
7036
            /* Ignore Python classes:
7037
               they never define their own C-level setattro. */
7038
967k
        }
7039
1.01M
        else if (base->tp_setattro == type->tp_setattro) {
  Branch (7039:18): [True: 14, False: 1.01M]
7040
14
            defining_type = base;
7041
14
            break;
7042
14
        }
7043
1.98M
    }
7044
7045
    /* Reject calls that jump over intermediate C-level overrides. */
7046
1.17M
    for (PyTypeObject *base = defining_type; base; base = base->tp_base) {
  Branch (7046:46): [True: 1.17M, False: 0]
7047
1.17M
        if (base->tp_setattro == func) {
  Branch (7047:13): [True: 463k, False: 707k]
7048
            /* 'func' is the right slot function to call. */
7049
463k
            break;
7050
463k
        }
7051
707k
        else if (base->tp_setattro != slot_tp_setattro) {
  Branch (7051:18): [True: 3, False: 707k]
7052
            /* 'base' is not a Python class and overrides 'func'.
7053
               Its tp_setattro should be called instead. */
7054
3
            PyErr_Format(PyExc_TypeError,
7055
3
                         "can't apply this %s to %s object",
7056
3
                         what,
7057
3
                         type->tp_name);
7058
3
            return 0;
7059
3
        }
7060
1.17M
    }
7061
463k
    return 1;
7062
463k
}
7063
7064
static PyObject *
7065
wrap_setattr(PyObject *self, PyObject *args, void *wrapped)
7066
445k
{
7067
445k
    setattrofunc func = (setattrofunc)wrapped;
7068
445k
    int res;
7069
445k
    PyObject *name, *value;
7070
7071
445k
    if (!PyArg_UnpackTuple(args, "", 2, 2, &name, &value))
  Branch (7071:9): [True: 0, False: 445k]
7072
0
        return NULL;
7073
445k
    if (!hackcheck(self, func, "__setattr__"))
  Branch (7073:9): [True: 2, False: 445k]
7074
2
        return NULL;
7075
445k
    res = (*func)(self, name, value);
7076
445k
    if (res < 0)
  Branch (7076:9): [True: 3, False: 445k]
7077
3
        return NULL;
7078
445k
    Py_RETURN_NONE;
Line
Count
Source
661
445k
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
445k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
445k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
445k
#  define _Py_CAST(type, expr) ((type)(expr))
7079
445k
}
7080
7081
static PyObject *
7082
wrap_delattr(PyObject *self, PyObject *args, void *wrapped)
7083
18.2k
{
7084
18.2k
    setattrofunc func = (setattrofunc)wrapped;
7085
18.2k
    int res;
7086
18.2k
    PyObject *name;
7087
7088
18.2k
    if (!check_num_args(args, 1))
  Branch (7088:9): [True: 1, False: 18.2k]
7089
1
        return NULL;
7090
18.2k
    name = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
18.2k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
18.2k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
18.2k
#  define _Py_CAST(type, expr) ((type)(expr))
7091
18.2k
    if (!hackcheck(self, func, "__delattr__"))
  Branch (7091:9): [True: 1, False: 18.2k]
7092
1
        return NULL;
7093
18.2k
    res = (*func)(self, name, NULL);
7094
18.2k
    if (res < 0)
  Branch (7094:9): [True: 20, False: 18.1k]
7095
20
        return NULL;
7096
18.2k
    Py_RETURN_NONE;
Line
Count
Source
661
18.1k
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
18.1k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
18.1k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
18.1k
#  define _Py_CAST(type, expr) ((type)(expr))
7097
18.2k
}
7098
7099
static PyObject *
7100
wrap_hashfunc(PyObject *self, PyObject *args, void *wrapped)
7101
606k
{
7102
606k
    hashfunc func = (hashfunc)wrapped;
7103
606k
    Py_hash_t res;
7104
7105
606k
    if (!check_num_args(args, 0))
  Branch (7105:9): [True: 0, False: 606k]
7106
0
        return NULL;
7107
606k
    res = (*func)(self);
7108
606k
    if (res == -1 && PyErr_Occurred())
  Branch (7108:9): [True: 4, False: 606k]
  Branch (7108:22): [True: 4, False: 0]
7109
4
        return NULL;
7110
606k
    return PyLong_FromSsize_t(res);
7111
606k
}
7112
7113
static PyObject *
7114
wrap_call(PyObject *self, PyObject *args, void *wrapped, PyObject *kwds)
7115
24
{
7116
24
    ternaryfunc func = (ternaryfunc)wrapped;
7117
7118
24
    return (*func)(self, args, kwds);
7119
24
}
7120
7121
static PyObject *
7122
wrap_del(PyObject *self, PyObject *args, void *wrapped)
7123
9
{
7124
9
    destructor func = (destructor)wrapped;
7125
7126
9
    if (!check_num_args(args, 0))
  Branch (7126:9): [True: 0, False: 9]
7127
0
        return NULL;
7128
7129
9
    (*func)(self);
7130
9
    Py_RETURN_NONE;
Line
Count
Source
661
9
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
9
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
7131
9
}
7132
7133
static PyObject *
7134
wrap_richcmpfunc(PyObject *self, PyObject *args, void *wrapped, int op)
7135
125k
{
7136
125k
    richcmpfunc func = (richcmpfunc)wrapped;
7137
125k
    PyObject *other;
7138
7139
125k
    if (!check_num_args(args, 1))
  Branch (7139:9): [True: 0, False: 125k]
7140
0
        return NULL;
7141
125k
    other = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
125k
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
125k
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
125k
#  define _Py_CAST(type, expr) ((type)(expr))
7142
125k
    return (*func)(self, other, op);
7143
125k
}
7144
7145
#undef RICHCMP_WRAPPER
7146
#define RICHCMP_WRAPPER(NAME, OP) \
7147
static PyObject * \
7148
125k
richcmp_##NAME(PyObject *self, PyObject *args, void *wrapped) \
7149
125k
{ \
7150
125k
    return wrap_richcmpfunc(self, args, wrapped, OP); \
7151
125k
}
typeobject.c:richcmp_lt
Line
Count
Source
7148
54
richcmp_##NAME(PyObject *self, PyObject *args, void *wrapped) \
7149
54
{ \
7150
54
    return wrap_richcmpfunc(self, args, wrapped, OP); \
7151
54
}
typeobject.c:richcmp_le
Line
Count
Source
7148
29
richcmp_##NAME(PyObject *self, PyObject *args, void *wrapped) \
7149
29
{ \
7150
29
    return wrap_richcmpfunc(self, args, wrapped, OP); \
7151
29
}
typeobject.c:richcmp_eq
Line
Count
Source
7148
118k
richcmp_##NAME(PyObject *self, PyObject *args, void *wrapped) \
7149
118k
{ \
7150
118k
    return wrap_richcmpfunc(self, args, wrapped, OP); \
7151
118k
}
typeobject.c:richcmp_ne
Line
Count
Source
7148
7.43k
richcmp_##NAME(PyObject *self, PyObject *args, void *wrapped) \
7149
7.43k
{ \
7150
7.43k
    return wrap_richcmpfunc(self, args, wrapped, OP); \
7151
7.43k
}
typeobject.c:richcmp_gt
Line
Count
Source
7148
37
richcmp_##NAME(PyObject *self, PyObject *args, void *wrapped) \
7149
37
{ \
7150
37
    return wrap_richcmpfunc(self, args, wrapped, OP); \
7151
37
}
typeobject.c:richcmp_ge
Line
Count
Source
7148
27
richcmp_##NAME(PyObject *self, PyObject *args, void *wrapped) \
7149
27
{ \
7150
27
    return wrap_richcmpfunc(self, args, wrapped, OP); \
7151
27
}
7152
7153
RICHCMP_WRAPPER(lt, Py_LT)
7154
RICHCMP_WRAPPER(le, Py_LE)
7155
RICHCMP_WRAPPER(eq, Py_EQ)
7156
RICHCMP_WRAPPER(ne, Py_NE)
7157
RICHCMP_WRAPPER(gt, Py_GT)
7158
RICHCMP_WRAPPER(ge, Py_GE)
7159
7160
static PyObject *
7161
wrap_next(PyObject *self, PyObject *args, void *wrapped)
7162
210k
{
7163
210k
    unaryfunc func = (unaryfunc)wrapped;
7164
210k
    PyObject *res;
7165
7166
210k
    if (!check_num_args(args, 0))
  Branch (7166:9): [True: 0, False: 210k]
7167
0
        return NULL;
7168
210k
    res = (*func)(self);
7169
210k
    if (res == NULL && !PyErr_Occurred())
  Branch (7169:9): [True: 5.99k, False: 204k]
  Branch (7169:24): [True: 5.91k, False: 71]
7170
5.91k
        PyErr_SetNone(PyExc_StopIteration);
7171
210k
    return res;
7172
210k
}
7173
7174
static PyObject *
7175
wrap_descr_get(PyObject *self, PyObject *args, void *wrapped)
7176
1.16k
{
7177
1.16k
    descrgetfunc func = (descrgetfunc)wrapped;
7178
1.16k
    PyObject *obj;
7179
1.16k
    PyObject *type = NULL;
7180
7181
1.16k
    if (!PyArg_UnpackTuple(args, "", 1, 2, &obj, &type))
  Branch (7181:9): [True: 0, False: 1.16k]
7182
0
        return NULL;
7183
1.16k
    if (obj == Py_None)
Line
Count
Source
654
1.16k
#define Py_None (&_Py_NoneStruct)
  Branch (7183:9): [True: 68, False: 1.10k]
7184
68
        obj = NULL;
7185
1.16k
    if (type == Py_None)
Line
Count
Source
654
1.16k
#define Py_None (&_Py_NoneStruct)
  Branch (7185:9): [True: 1, False: 1.16k]
7186
1
        type = NULL;
7187
1.16k
    if (type == NULL && obj == NULL) {
  Branch (7187:9): [True: 1.01k, False: 154]
  Branch (7187:25): [True: 1, False: 1.01k]
7188
1
        PyErr_SetString(PyExc_TypeError,
7189
1
                        "__get__(None, None) is invalid");
7190
1
        return NULL;
7191
1
    }
7192
1.16k
    return (*func)(self, obj, type);
7193
1.16k
}
7194
7195
static PyObject *
7196
wrap_descr_set(PyObject *self, PyObject *args, void *wrapped)
7197
585
{
7198
585
    descrsetfunc func = (descrsetfunc)wrapped;
7199
585
    PyObject *obj, *value;
7200
585
    int ret;
7201
7202
585
    if (!PyArg_UnpackTuple(args, "", 2, 2, &obj, &value))
  Branch (7202:9): [True: 0, False: 585]
7203
0
        return NULL;
7204
585
    ret = (*func)(self, obj, value);
7205
585
    if (ret < 0)
  Branch (7205:9): [True: 16, False: 569]
7206
16
        return NULL;
7207
585
    Py_RETURN_NONE;
Line
Count
Source
661
569
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
569
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
569
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
569
#  define _Py_CAST(type, expr) ((type)(expr))
7208
585
}
7209
7210
static PyObject *
7211
wrap_descr_delete(PyObject *self, PyObject *args, void *wrapped)
7212
3
{
7213
3
    descrsetfunc func = (descrsetfunc)wrapped;
7214
3
    PyObject *obj;
7215
3
    int ret;
7216
7217
3
    if (!check_num_args(args, 1))
  Branch (7217:9): [True: 0, False: 3]
7218
0
        return NULL;
7219
3
    obj = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
3
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
3
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
7220
3
    ret = (*func)(self, obj, NULL);
7221
3
    if (ret < 0)
  Branch (7221:9): [True: 2, False: 1]
7222
2
        return NULL;
7223
3
    Py_RETURN_NONE;
Line
Count
Source
661
1
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
1
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
7224
3
}
7225
7226
static PyObject *
7227
wrap_init(PyObject *self, PyObject *args, void *wrapped, PyObject *kwds)
7228
823k
{
7229
823k
    initproc func = (initproc)wrapped;
7230
7231
823k
    if (func(self, args, kwds) < 0)
  Branch (7231:9): [True: 64, False: 823k]
7232
64
        return NULL;
7233
823k
    Py_RETURN_NONE;
Line
Count
Source
661
823k
#define Py_RETURN_NONE return Py_NewRef(Py_None)
Line
Count
Source
639
823k
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
823k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
823k
#  define _Py_CAST(type, expr) ((type)(expr))
7234
823k
}
7235
7236
static PyObject *
7237
tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
7238
3.18M
{
7239
3.18M
    PyTypeObject *staticbase;
7240
3.18M
    PyObject *arg0, *res;
7241
7242
3.18M
    if (self == NULL || !PyType_Check(self)) {
Line
Count
Source
788
3.18M
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
3.18M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.18M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7242:9): [True: 0, False: 3.18M]
  Branch (7242:25): [True: 0, False: 3.18M]
7243
0
        PyErr_Format(PyExc_SystemError,
7244
0
                     "__new__() called with non-type 'self'");
7245
0
        return NULL;
7246
0
    }
7247
3.18M
    PyTypeObject *type = (PyTypeObject *)self;
7248
7249
3.18M
    if (!PyTuple_Check(args) || PyTuple_GET_SIZE(args) < 1) {
Line
Count
Source
27
3.18M
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
Line
Count
Source
782
6.36M
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
    if (!PyTuple_Check(args) || PyTuple_GET_SIZE(args) < 1) {
Line
Count
Source
26
3.18M
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
3.18M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.18M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7249:9): [True: 0, False: 3.18M]
  Branch (7249:33): [True: 3, False: 3.18M]
7250
3
        PyErr_Format(PyExc_TypeError,
7251
3
                     "%s.__new__(): not enough arguments",
7252
3
                     type->tp_name);
7253
3
        return NULL;
7254
3
    }
7255
3.18M
    arg0 = PyTuple_GET_ITEM(args, 0);
Line
Count
Source
28
3.18M
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
3.18M
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
3.18M
#  define _Py_CAST(type, expr) ((type)(expr))
7256
3.18M
    if (!PyType_Check(arg0)) {
Line
Count
Source
788
3.18M
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
3.18M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.18M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7256:9): [True: 5, False: 3.18M]
7257
5
        PyErr_Format(PyExc_TypeError,
7258
5
                     "%s.__new__(X): X is not a type object (%s)",
7259
5
                     type->tp_name,
7260
5
                     Py_TYPE(arg0)->tp_name);
Line
Count
Source
138
5
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
7261
5
        return NULL;
7262
5
    }
7263
3.18M
    PyTypeObject *subtype = (PyTypeObject *)arg0;
7264
7265
3.18M
    if (!PyType_IsSubtype(subtype, type)) {
  Branch (7265:9): [True: 1, False: 3.18M]
7266
1
        PyErr_Format(PyExc_TypeError,
7267
1
                     "%s.__new__(%s): %s is not a subtype of %s",
7268
1
                     type->tp_name,
7269
1
                     subtype->tp_name,
7270
1
                     subtype->tp_name,
7271
1
                     type->tp_name);
7272
1
        return NULL;
7273
1
    }
7274
7275
    /* Check that the use doesn't do something silly and unsafe like
7276
       object.__new__(dict).  To do this, we check that the
7277
       most derived base that's not a heap type is this type. */
7278
3.18M
    staticbase = subtype;
7279
7.43M
    while (staticbase && (staticbase->tp_new == slot_tp_new))
  Branch (7279:12): [True: 7.43M, False: 0]
  Branch (7279:26): [True: 4.25M, False: 3.18M]
7280
4.25M
        staticbase = staticbase->tp_base;
7281
    /* If staticbase is NULL now, it is a really weird type.
7282
       In the spirit of backwards compatibility (?), just shut up. */
7283
3.18M
    if (staticbase && staticbase->tp_new != type->tp_new) {
  Branch (7283:9): [True: 3.18M, False: 0]
  Branch (7283:23): [True: 4, False: 3.18M]
7284
4
        PyErr_Format(PyExc_TypeError,
7285
4
                     "%s.__new__(%s) is not safe, use %s.__new__()",
7286
4
                     type->tp_name,
7287
4
                     subtype->tp_name,
7288
4
                     staticbase->tp_name);
7289
4
        return NULL;
7290
4
    }
7291
7292
3.18M
    args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
Line
Count
Source
26
3.18M
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
3.18M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.18M
#  define _Py_CAST(type, expr) ((type)(expr))
7293
3.18M
    if (args == NULL)
  Branch (7293:9): [True: 0, False: 3.18M]
7294
0
        return NULL;
7295
3.18M
    res = type->tp_new(subtype, args, kwds);
7296
3.18M
    Py_DECREF(args);
Line
Count
Source
548
3.18M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.18M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.18M
#  define _Py_CAST(type, expr) ((type)(expr))
7297
3.18M
    return res;
7298
3.18M
}
7299
7300
static struct PyMethodDef tp_new_methoddef[] = {
7301
    {"__new__", _PyCFunction_CAST(tp_new_wrapper), METH_VARARGS|METH_KEYWORDS,
7302
     PyDoc_STR("__new__($type, *args, **kwargs)\n--\n\n"
7303
               "Create and return a new object.  "
7304
               "See help(type) for accurate signature.")},
7305
    {0}
7306
};
7307
7308
static int
7309
add_tp_new_wrapper(PyTypeObject *type)
7310
17.0k
{
7311
17.0k
    int r = PyDict_Contains(type->tp_dict, &_Py_ID(__new__));
Line
Count
Source
374
17.0k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
17.0k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
17.0k
    _PyRuntime.global_objects.NAME
7312
17.0k
    if (r > 0) {
  Branch (7312:9): [True: 0, False: 17.0k]
7313
0
        return 0;
7314
0
    }
7315
17.0k
    if (r < 0) {
  Branch (7315:9): [True: 0, False: 17.0k]
7316
0
        return -1;
7317
0
    }
7318
7319
17.0k
    PyObject *func = PyCFunction_NewEx(tp_new_methoddef, (PyObject *)type, NULL);
Line
Count
Source
73
17.0k
#define PyCFunction_NewEx(ML, SELF, MOD) PyCMethod_New((ML), (SELF), (MOD), NULL)
7320
17.0k
    if (func == NULL) {
  Branch (7320:9): [True: 0, False: 17.0k]
7321
0
        return -1;
7322
0
    }
7323
17.0k
    r = PyDict_SetItem(type->tp_dict, &_Py_ID(__new__), func);
Line
Count
Source
374
17.0k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
17.0k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
17.0k
    _PyRuntime.global_objects.NAME
7324
17.0k
    Py_DECREF(func);
Line
Count
Source
548
17.0k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
17.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
17.0k
#  define _Py_CAST(type, expr) ((type)(expr))
7325
17.0k
    return r;
7326
17.0k
}
7327
7328
/* Slot wrappers that call the corresponding __foo__ slot.  See comments
7329
   below at override_slots() for more explanation. */
7330
7331
#define SLOT0(FUNCNAME, DUNDER) \
7332
static PyObject * \
7333
369k
FUNCNAME(PyObject *self) \
7334
369k
{ \
7335
369k
    PyObject* stack[1] = {self}; \
7336
369k
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
293k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
293k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
293k
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
11.5k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
11.5k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
11.5k
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
11
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
11
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
11
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
39.9k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
39.9k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
39.9k
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
274
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
274
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
274
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
22.1k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
22.1k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
22.1k
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
1.98k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1.98k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1.98k
    _PyRuntime.global_objects.NAME
7337
369k
}
typeobject.c:slot_tp_str
Line
Count
Source
7333
293k
FUNCNAME(PyObject *self) \
7334
293k
{ \
7335
293k
    PyObject* stack[1] = {self}; \
7336
293k
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
293k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
293k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
293k
    _PyRuntime.global_objects.NAME
7337
293k
}
typeobject.c:slot_nb_negative
Line
Count
Source
7333
11.5k
FUNCNAME(PyObject *self) \
7334
11.5k
{ \
7335
11.5k
    PyObject* stack[1] = {self}; \
7336
11.5k
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
11.5k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
11.5k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
11.5k
    _PyRuntime.global_objects.NAME
7337
11.5k
}
typeobject.c:slot_nb_positive
Line
Count
Source
7333
11
FUNCNAME(PyObject *self) \
7334
11
{ \
7335
11
    PyObject* stack[1] = {self}; \
7336
11
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
11
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
11
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
11
    _PyRuntime.global_objects.NAME
7337
11
}
typeobject.c:slot_nb_absolute
Line
Count
Source
7333
39.9k
FUNCNAME(PyObject *self) \
7334
39.9k
{ \
7335
39.9k
    PyObject* stack[1] = {self}; \
7336
39.9k
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
39.9k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
39.9k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
39.9k
    _PyRuntime.global_objects.NAME
7337
39.9k
}
typeobject.c:slot_nb_invert
Line
Count
Source
7333
274
FUNCNAME(PyObject *self) \
7334
274
{ \
7335
274
    PyObject* stack[1] = {self}; \
7336
274
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
274
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
274
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
274
    _PyRuntime.global_objects.NAME
7337
274
}
typeobject.c:slot_nb_int
Line
Count
Source
7333
22.1k
FUNCNAME(PyObject *self) \
7334
22.1k
{ \
7335
22.1k
    PyObject* stack[1] = {self}; \
7336
22.1k
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
22.1k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
22.1k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
22.1k
    _PyRuntime.global_objects.NAME
7337
22.1k
}
typeobject.c:slot_nb_float
Line
Count
Source
7333
1.98k
FUNCNAME(PyObject *self) \
7334
1.98k
{ \
7335
1.98k
    PyObject* stack[1] = {self}; \
7336
1.98k
    return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
Line
Count
Source
374
1.98k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1.98k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1.98k
    _PyRuntime.global_objects.NAME
7337
1.98k
}
7338
7339
#define SLOT1(FUNCNAME, DUNDER, ARG1TYPE) \
7340
static PyObject * \
7341
759k
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
759k
{ \
7343
759k
    PyObject* stack[2] = {self, arg1}; \
7344
759k
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
22
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
22
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
22
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
11
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
11
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
11
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
18
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
18
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
18
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
6
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
6
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
6
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
6
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
6
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
6
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
6
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
6
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
6
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
14
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
14
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
14
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
10
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
10
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
10
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
36
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
36
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
36
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
7
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
7
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
7
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
7
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
7
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
7
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
9
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
9
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
9
    _PyRuntime.global_objects.NAME
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
759k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
759k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
759k
    _PyRuntime.global_objects.NAME
7345
759k
}
typeobject.c:slot_nb_inplace_add
Line
Count
Source
7341
22
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
22
{ \
7343
22
    PyObject* stack[2] = {self, arg1}; \
7344
22
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
22
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
22
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
22
    _PyRuntime.global_objects.NAME
7345
22
}
typeobject.c:slot_nb_inplace_subtract
Line
Count
Source
7341
11
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
11
{ \
7343
11
    PyObject* stack[2] = {self, arg1}; \
7344
11
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
11
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
11
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
11
    _PyRuntime.global_objects.NAME
7345
11
}
typeobject.c:slot_nb_inplace_multiply
Line
Count
Source
7341
18
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
18
{ \
7343
18
    PyObject* stack[2] = {self, arg1}; \
7344
18
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
18
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
18
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
18
    _PyRuntime.global_objects.NAME
7345
18
}
typeobject.c:slot_nb_inplace_remainder
Line
Count
Source
7341
6
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
6
{ \
7343
6
    PyObject* stack[2] = {self, arg1}; \
7344
6
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
6
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
6
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
6
    _PyRuntime.global_objects.NAME
7345
6
}
typeobject.c:slot_nb_inplace_lshift
Line
Count
Source
7341
6
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
6
{ \
7343
6
    PyObject* stack[2] = {self, arg1}; \
7344
6
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
6
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
6
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
6
    _PyRuntime.global_objects.NAME
7345
6
}
typeobject.c:slot_nb_inplace_rshift
Line
Count
Source
7341
6
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
6
{ \
7343
6
    PyObject* stack[2] = {self, arg1}; \
7344
6
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
6
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
6
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
6
    _PyRuntime.global_objects.NAME
7345
6
}
typeobject.c:slot_nb_inplace_and
Line
Count
Source
7341
14
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
14
{ \
7343
14
    PyObject* stack[2] = {self, arg1}; \
7344
14
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
14
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
14
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
14
    _PyRuntime.global_objects.NAME
7345
14
}
typeobject.c:slot_nb_inplace_xor
Line
Count
Source
7341
10
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
10
{ \
7343
10
    PyObject* stack[2] = {self, arg1}; \
7344
10
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
10
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
10
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
10
    _PyRuntime.global_objects.NAME
7345
10
}
typeobject.c:slot_nb_inplace_or
Line
Count
Source
7341
36
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
36
{ \
7343
36
    PyObject* stack[2] = {self, arg1}; \
7344
36
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
36
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
36
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
36
    _PyRuntime.global_objects.NAME
7345
36
}
typeobject.c:slot_nb_inplace_floor_divide
Line
Count
Source
7341
7
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
7
{ \
7343
7
    PyObject* stack[2] = {self, arg1}; \
7344
7
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
7
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
7
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
7
    _PyRuntime.global_objects.NAME
7345
7
}
typeobject.c:slot_nb_inplace_true_divide
Line
Count
Source
7341
7
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
7
{ \
7343
7
    PyObject* stack[2] = {self, arg1}; \
7344
7
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
7
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
7
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
7
    _PyRuntime.global_objects.NAME
7345
7
}
typeobject.c:slot_nb_inplace_matrix_multiply
Line
Count
Source
7341
9
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
9
{ \
7343
9
    PyObject* stack[2] = {self, arg1}; \
7344
9
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
9
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
9
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
9
    _PyRuntime.global_objects.NAME
7345
9
}
typeobject.c:slot_mp_subscript
Line
Count
Source
7341
759k
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
7342
759k
{ \
7343
759k
    PyObject* stack[2] = {self, arg1}; \
7344
759k
    return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
759k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
759k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
759k
    _PyRuntime.global_objects.NAME
7345
759k
}
7346
7347
/* Boolean helper for SLOT1BINFULL().
7348
   right.__class__ is a nontrivial subclass of left.__class__. */
7349
static int
7350
method_is_overloaded(PyObject *left, PyObject *right, PyObject *name)
7351
10
{
7352
10
    PyObject *a, *b;
7353
10
    int ok;
7354
7355
10
    if (_PyObject_LookupAttr((PyObject *)(Py_TYPE(right)), name, &b) < 0) {
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7355:9): [True: 0, False: 10]
7356
0
        return -1;
7357
0
    }
7358
10
    if (b == NULL) {
  Branch (7358:9): [True: 0, False: 10]
7359
        /* If right doesn't have it, it's not overloaded */
7360
0
        return 0;
7361
0
    }
7362
7363
10
    if (_PyObject_LookupAttr((PyObject *)(Py_TYPE(left)), name, &a) < 0) {
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7363:9): [True: 0, False: 10]
7364
0
        Py_DECREF(b);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7365
0
        return -1;
7366
0
    }
7367
10
    if (a == NULL) {
  Branch (7367:9): [True: 0, False: 10]
7368
0
        Py_DECREF(b);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7369
        /* If right has it but left doesn't, it's overloaded */
7370
0
        return 1;
7371
0
    }
7372
7373
10
    ok = PyObject_RichCompareBool(a, b, Py_NE);
Line
Count
Source
677
10
#define Py_NE 3
7374
10
    Py_DECREF(a);
Line
Count
Source
548
10
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
7375
10
    Py_DECREF(b);
Line
Count
Source
548
10
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
7376
10
    return ok;
7377
10
}
7378
7379
7380
#define SLOT1BINFULL(FUNCNAME, TESTFUNC, SLOTNAME, DUNDER, RDUNDER) \
7381
static PyObject * \
7382
500k
FUNCNAME(PyObject *self, PyObject *other) \
7383
500k
{ \
7384
500k
    PyObject* stack[2]; \
7385
500k
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
500k
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
312k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
156k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
156k
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
46.1k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
23.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
23.0k
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
5.17k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
2.58k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.58k
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
98
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
49
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
49
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
5.19k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
2.59k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.59k
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
234k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
22
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
24
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
52.4k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
26.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
26.2k
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
448
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
224
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
224
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
12.5k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
6.28k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6.28k
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
3.48k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
1.74k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.74k
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
327k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
163k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
163k
#  define _Py_CAST(type, expr) ((type)(expr))
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
38
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
19
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
19
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 16.8k, False: 139k]
  Branch (7386:20): [True: 3.08k, False: 19.9k]
  Branch (7386:20): [True: 2.21k, False: 375]
  Branch (7386:20): [True: 29, False: 20]
  Branch (7386:20): [True: 48, False: 2.55k]
  Branch (7386:20): [True: 117k, False: 22]
  Branch (7386:20): [True: 9, False: 2]
  Branch (7386:20): [True: 10, False: 2]
  Branch (7386:20): [True: 21.3k, False: 4.89k]
  Branch (7386:20): [True: 166, False: 58]
  Branch (7386:20): [True: 1.24k, False: 5.03k]
  Branch (7386:20): [True: 66, False: 1.67k]
  Branch (7386:20): [True: 141k, False: 21.8k]
  Branch (7386:20): [True: 16, False: 3]
7387
500k
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
16.8k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16.8k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
3.08k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3.08k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.08k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
2.21k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.21k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.21k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
29
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
29
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
29
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
48
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
48
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
48
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
117k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
9
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
21.3k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
21.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21.3k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
166
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
166
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
166
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
1.24k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1.24k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.24k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
66
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
66
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
66
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
141k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
141k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
141k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
16
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 16.8k, False: 6]
  Branch (7387:9): [True: 3.08k, False: 2]
  Branch (7387:9): [True: 2.21k, False: 0]
  Branch (7387:9): [True: 29, False: 0]
  Branch (7387:9): [True: 48, False: 0]
  Branch (7387:9): [True: 117k, False: 0]
  Branch (7387:9): [True: 9, False: 0]
  Branch (7387:9): [True: 10, False: 0]
  Branch (7387:9): [True: 21.3k, False: 1]
  Branch (7387:9): [True: 165, False: 1]
  Branch (7387:9): [True: 1.24k, False: 4]
  Branch (7387:9): [True: 66, False: 0]
  Branch (7387:9): [True: 141k, False: 0]
  Branch (7387:9): [True: 16, False: 0]
7388
500k
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
16.8k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16.8k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
3.08k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3.08k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.08k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
2.21k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.21k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.21k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
29
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
29
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
29
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
48
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
48
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
48
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
117k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
9
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
21.3k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
21.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21.3k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
165
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
165
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
165
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
1.24k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1.24k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.24k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
66
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
66
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
66
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
141k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
141k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
141k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
16
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 16.7k, False: 123]
  Branch (7388:9): [True: 2.93k, False: 149]
  Branch (7388:9): [True: 1.79k, False: 418]
  Branch (7388:9): [True: 11, False: 18]
  Branch (7388:9): [True: 9, False: 39]
  Branch (7388:9): [True: 18, False: 117k]
  Branch (7388:9): [True: 3, False: 6]
  Branch (7388:9): [True: 4, False: 6]
  Branch (7388:9): [True: 20.2k, False: 1.02k]
  Branch (7388:9): [True: 80, False: 85]
  Branch (7388:9): [True: 886, False: 359]
  Branch (7388:9): [True: 35, False: 31]
  Branch (7388:9): [True: 207, False: 141k]
  Branch (7388:9): [True: 5, False: 11]
7389
500k
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
156k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
156k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
156k
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
23.0k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
23.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
23.0k
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
2.58k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.58k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.58k
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
49
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
49
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
49
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
2.59k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.59k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.59k
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
117k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
11
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
12
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
26.2k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
26.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
26.2k
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
224
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
224
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
224
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
6.28k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
6.28k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6.28k
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
1.74k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1.74k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.74k
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
163k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
163k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
163k
#  define _Py_CAST(type, expr) ((type)(expr))
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
19
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
19
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
19
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 156k, False: 2]
  Branch (7389:9): [True: 23.0k, False: 0]
  Branch (7389:9): [True: 2.58k, False: 0]
  Branch (7389:9): [True: 49, False: 0]
  Branch (7389:9): [True: 2.59k, False: 0]
  Branch (7389:9): [True: 117k, False: 1]
  Branch (7389:9): [True: 11, False: 0]
  Branch (7389:9): [True: 11, False: 1]
  Branch (7389:9): [True: 26.2k, False: 0]
  Branch (7389:9): [True: 224, False: 0]
  Branch (7389:9): [True: 6.28k, False: 0]
  Branch (7389:9): [True: 1.74k, False: 0]
  Branch (7389:9): [True: 163k, False: 0]
  Branch (7389:9): [True: 19, False: 0]
7390
500k
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
156k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
156k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
156k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
23.0k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
23.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
23.0k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
2.58k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.58k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.58k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
49
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
49
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
49
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
2.59k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.59k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.59k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
117k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
11
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
11
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
26.2k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
26.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
26.2k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
224
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
224
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
224
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
6.28k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
6.28k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6.28k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
1.74k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1.74k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.74k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
163k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
163k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
163k
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
19
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
19
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
19
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 155k, False: 696]
  Branch (7390:9): [True: 23.0k, False: 38]
  Branch (7390:9): [True: 805, False: 1.78k]
  Branch (7390:9): [True: 41, False: 8]
  Branch (7390:9): [True: 2.59k, False: 7]
  Branch (7390:9): [True: 117k, False: 14]
  Branch (7390:9): [True: 8, False: 3]
  Branch (7390:9): [True: 8, False: 3]
  Branch (7390:9): [True: 5.91k, False: 20.2k]
  Branch (7390:9): [True: 145, False: 79]
  Branch (7390:9): [True: 5.41k, False: 873]
  Branch (7390:9): [True: 1.71k, False: 25]
  Branch (7390:9): [True: 163k, False: 179]
  Branch (7390:9): [True: 14, False: 5]
7391
476k
        PyObject *r; \
7392
476k
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
16.0k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16.0k
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
2.89k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.89k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.89k
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
12
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
2
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
13
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
13
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
28
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
28
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
28
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
16.0k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16.0k
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
2.89k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.89k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.89k
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
12
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
2
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
13
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
13
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
28
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
28
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
28
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 16.0k, False: 139k]
  Branch (7392:25): [True: 0, False: 16.0k]
  Branch (7392:13): [True: 2.89k, False: 20.1k]
  Branch (7392:25): [True: 0, False: 2.89k]
  Branch (7392:13): [True: 12, False: 793]
  Branch (7392:25): [True: 0, False: 12]
  Branch (7392:13): [True: 3, False: 38]
  Branch (7392:25): [True: 1, False: 2]
  Branch (7392:13): [True: 2, False: 2.59k]
  Branch (7392:25): [True: 0, False: 2]
  Branch (7392:13): [True: 3, False: 117k]
  Branch (7392:25): [True: 0, False: 3]
  Branch (7392:13): [True: 0, False: 8]
  Branch (7392:25): [True: 0, False: 0]
  Branch (7392:13): [True: 0, False: 8]
  Branch (7392:25): [True: 0, False: 0]
  Branch (7392:13): [True: 1, False: 5.91k]
  Branch (7392:25): [True: 0, False: 1]
  Branch (7392:13): [True: 1, False: 144]
  Branch (7392:25): [True: 0, False: 1]
  Branch (7392:13): [True: 13, False: 5.39k]
  Branch (7392:25): [True: 7, False: 6]
  Branch (7392:13): [True: 10, False: 1.70k]
  Branch (7392:25): [True: 2, False: 8]
  Branch (7392:13): [True: 28, False: 163k]
  Branch (7392:25): [True: 0, False: 28]
  Branch (7392:13): [True: 0, False: 14]
  Branch (7392:25): [True: 0, False: 0]
7393
10
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
7
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
7
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
7
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
2
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
2
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
2
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
10
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
  Branch (7394:17): [True: 0, False: 0]
  Branch (7394:17): [True: 0, False: 0]
  Branch (7394:17): [True: 0, False: 1]
  Branch (7394:17): [True: 0, False: 0]
  Branch (7394:17): [True: 0, False: 0]
  Branch (7394:17): [True: 0, False: 0]
  Branch (7394:17): [True: 0, False: 0]
  Branch (7394:17): [True: 0, False: 0]
  Branch (7394:17): [True: 0, False: 0]
  Branch (7394:17): [True: 0, False: 7]
  Branch (7394:17): [True: 0, False: 2]
  Branch (7394:17): [True: 0, False: 0]
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
10
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
  Branch (7397:17): [True: 0, False: 0]
  Branch (7397:17): [True: 0, False: 0]
  Branch (7397:17): [True: 1, False: 0]
  Branch (7397:17): [True: 0, False: 0]
  Branch (7397:17): [True: 0, False: 0]
  Branch (7397:17): [True: 0, False: 0]
  Branch (7397:17): [True: 0, False: 0]
  Branch (7397:17): [True: 0, False: 0]
  Branch (7397:17): [True: 0, False: 0]
  Branch (7397:17): [True: 1, False: 6]
  Branch (7397:17): [True: 1, False: 1]
  Branch (7397:17): [True: 0, False: 0]
  Branch (7397:17): [True: 0, False: 0]
7398
3
                stack[0] = other; \
7399
3
                stack[1] = self; \
7400
3
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
3
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
1
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
1
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
1
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
  Branch (7401:21): [True: 0, False: 0]
  Branch (7401:21): [True: 0, False: 0]
  Branch (7401:21): [True: 1, False: 0]
  Branch (7401:21): [True: 0, False: 0]
  Branch (7401:21): [True: 0, False: 0]
  Branch (7401:21): [True: 0, False: 0]
  Branch (7401:21): [True: 0, False: 0]
  Branch (7401:21): [True: 0, False: 0]
  Branch (7401:21): [True: 0, False: 0]
  Branch (7401:21): [True: 1, False: 0]
  Branch (7401:21): [True: 1, False: 0]
  Branch (7401:21): [True: 0, False: 0]
  Branch (7401:21): [True: 0, False: 0]
7402
3
                    return r; \
7403
3
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
10
        } \
7407
476k
        stack[0] = self; \
7408
476k
        stack[1] = other; \
7409
476k
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
155k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
155k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
155k
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
23.0k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
23.0k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
23.0k
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
805
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
805
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
805
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
40
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
40
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
40
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
2.59k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
2.59k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
2.59k
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
117k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
117k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
117k
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
8
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
8
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
8
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
8
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
8
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
8
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
5.91k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
5.91k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
5.91k
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
145
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
145
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
145
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
5.41k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
5.41k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
5.41k
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
1.71k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1.71k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1.71k
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
163k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
163k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
163k
    _PyRuntime.global_objects.NAME
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
14
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
14
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
14
    _PyRuntime.global_objects.NAME
7410
476k
        if (r != Py_NotImplemented || \
Line
Count
Source
668
311k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
46.0k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
1.61k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
80
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
5.18k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
234k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
16
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
16
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
11.8k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
290
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
10.8k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
3.43k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
326k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
        if (r != Py_NotImplemented || \
Line
Count
Source
668
28
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 155k, False: 42]
  Branch (7410:13): [True: 23.0k, False: 23]
  Branch (7410:13): [True: 794, False: 11]
  Branch (7410:13): [True: 32, False: 8]
  Branch (7410:13): [True: 2.58k, False: 5]
  Branch (7410:13): [True: 117k, False: 7]
  Branch (7410:13): [True: 2, False: 6]
  Branch (7410:13): [True: 2, False: 6]
  Branch (7410:13): [True: 5.91k, False: 7]
  Branch (7410:13): [True: 138, False: 7]
  Branch (7410:13): [True: 5.39k, False: 16]
  Branch (7410:13): [True: 1.70k, False: 11]
  Branch (7410:13): [True: 163k, False: 10]
  Branch (7410:13): [True: 8, False: 6]
7411
476k
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
42
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
42
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
42
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 9, False: 33]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
23
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
23
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
23
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 21]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
11
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 9]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
8
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
8
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 6]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
5
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 1, False: 4]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
7
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
7
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 5]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
6
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 4]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
6
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 4]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
7
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
7
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 5]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
7
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
7
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 5]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
16
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
16
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 14]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
11
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 9]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
10
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 8]
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
6
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 4]
7412
476k
            return r; \
7413
476k
        Py_DECREF(r); \
Line
Count
Source
548
33
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
33
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
33
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
21
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
21
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
9
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
6
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
5
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
5
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
5
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
14
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
14
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
9
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
8
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
8
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8
#  define _Py_CAST(type, expr) ((type)(expr))
        Py_DECREF(r); \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7414
131
    } \
7415
500k
    if (do_other) { \
  Branch (7415:9): [True: 712, False: 19]
  Branch (7415:9): [True: 45, False: 14]
  Branch (7415:9): [True: 1.78k, False: 8]
  Branch (7415:9): [True: 9, False: 5]
  Branch (7415:9): [True: 8, False: 3]
  Branch (7415:9): [True: 16, False: 4]
  Branch (7415:9): [True: 3, False: 4]
  Branch (7415:9): [True: 4, False: 4]
  Branch (7415:9): [True: 20.2k, False: 4]
  Branch (7415:9): [True: 80, False: 4]
  Branch (7415:9): [True: 874, False: 13]
  Branch (7415:9): [True: 26, False: 8]
  Branch (7415:9): [True: 181, False: 6]
  Branch (7415:9): [True: 5, False: 4]
7416
24.0k
        stack[0] = other; \
7417
24.0k
        stack[1] = self; \
7418
24.0k
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
712
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
712
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
712
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
45
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
45
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
45
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
1.78k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1.78k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1.78k
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
9
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
9
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
9
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
8
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
8
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
8
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
16
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
16
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
16
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
3
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
3
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
3
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
4
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
4
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
4
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
20.2k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
20.2k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
20.2k
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
80
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
80
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
80
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
874
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
874
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
874
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
26
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
26
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
26
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
181
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
181
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
181
    _PyRuntime.global_objects.NAME
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
5
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
5
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
5
    _PyRuntime.global_objects.NAME
7419
24.0k
    } \
7420
24.1k
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
19
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
19
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
19
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
19
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
14
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
14
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
14
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
8
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
8
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
8
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
5
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
5
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
3
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
3
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
13
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
13
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
13
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
8
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
8
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
8
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
6
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
6
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7421
24.1k
}
typeobject.c:slot_nb_add
Line
Count
Source
7382
156k
FUNCNAME(PyObject *self, PyObject *other) \
7383
156k
{ \
7384
156k
    PyObject* stack[2]; \
7385
156k
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
156k
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
312k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
156k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
156k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 16.8k, False: 139k]
7387
156k
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
16.8k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16.8k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 16.8k, False: 6]
7388
156k
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
16.8k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16.8k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16.8k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 16.7k, False: 123]
7389
156k
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
156k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
156k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
156k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 156k, False: 2]
7390
156k
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
156k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
156k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
156k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 155k, False: 696]
7391
155k
        PyObject *r; \
7392
155k
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
16.0k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16.0k
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
16.0k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16.0k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 16.0k, False: 139k]
  Branch (7392:25): [True: 0, False: 16.0k]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
155k
        stack[0] = self; \
7408
155k
        stack[1] = other; \
7409
155k
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
155k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
155k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
155k
    _PyRuntime.global_objects.NAME
7410
155k
        if (r != Py_NotImplemented || \
Line
Count
Source
668
311k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 155k, False: 42]
7411
155k
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
42
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
42
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
42
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 9, False: 33]
7412
155k
            return r; \
7413
155k
        Py_DECREF(r); \
Line
Count
Source
548
33
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
33
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
33
#  define _Py_CAST(type, expr) ((type)(expr))
7414
33
    } \
7415
156k
    if (do_other) { \
  Branch (7415:9): [True: 712, False: 19]
7416
712
        stack[0] = other; \
7417
712
        stack[1] = self; \
7418
712
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
712
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
712
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
712
    _PyRuntime.global_objects.NAME
7419
712
    } \
7420
731
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
19
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
19
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
19
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
19
#  define _Py_CAST(type, expr) ((type)(expr))
7421
731
}
typeobject.c:slot_nb_subtract
Line
Count
Source
7382
23.0k
FUNCNAME(PyObject *self, PyObject *other) \
7383
23.0k
{ \
7384
23.0k
    PyObject* stack[2]; \
7385
23.0k
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
23.0k
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
46.1k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
23.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
23.0k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 3.08k, False: 19.9k]
7387
23.0k
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
3.08k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3.08k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.08k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 3.08k, False: 2]
7388
23.0k
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
3.08k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3.08k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.08k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 2.93k, False: 149]
7389
23.0k
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
23.0k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
23.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
23.0k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 23.0k, False: 0]
7390
23.0k
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
23.0k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
23.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
23.0k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 23.0k, False: 38]
7391
23.0k
        PyObject *r; \
7392
23.0k
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
2.89k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.89k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.89k
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
2.89k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.89k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.89k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 2.89k, False: 20.1k]
  Branch (7392:25): [True: 0, False: 2.89k]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
23.0k
        stack[0] = self; \
7408
23.0k
        stack[1] = other; \
7409
23.0k
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
23.0k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
23.0k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
23.0k
    _PyRuntime.global_objects.NAME
7410
23.0k
        if (r != Py_NotImplemented || \
Line
Count
Source
668
46.0k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 23.0k, False: 23]
7411
23.0k
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
23
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
23
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
23
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 21]
7412
23.0k
            return r; \
7413
23.0k
        Py_DECREF(r); \
Line
Count
Source
548
21
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
21
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21
#  define _Py_CAST(type, expr) ((type)(expr))
7414
21
    } \
7415
23.0k
    if (do_other) { \
  Branch (7415:9): [True: 45, False: 14]
7416
45
        stack[0] = other; \
7417
45
        stack[1] = self; \
7418
45
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
45
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
45
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
45
    _PyRuntime.global_objects.NAME
7419
45
    } \
7420
59
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
14
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
14
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
14
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14
#  define _Py_CAST(type, expr) ((type)(expr))
7421
59
}
typeobject.c:slot_nb_multiply
Line
Count
Source
7382
2.58k
FUNCNAME(PyObject *self, PyObject *other) \
7383
2.58k
{ \
7384
2.58k
    PyObject* stack[2]; \
7385
2.58k
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
2.58k
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
5.17k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
2.58k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.58k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 2.21k, False: 375]
7387
2.58k
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
2.21k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.21k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.21k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 2.21k, False: 0]
7388
2.58k
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
2.21k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.21k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.21k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 1.79k, False: 418]
7389
2.58k
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
2.58k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.58k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.58k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 2.58k, False: 0]
7390
2.58k
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
2.58k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.58k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.58k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 805, False: 1.78k]
7391
805
        PyObject *r; \
7392
805
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
12
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
12
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 12, False: 793]
  Branch (7392:25): [True: 0, False: 12]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
805
        stack[0] = self; \
7408
805
        stack[1] = other; \
7409
805
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
805
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
805
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
805
    _PyRuntime.global_objects.NAME
7410
805
        if (r != Py_NotImplemented || \
Line
Count
Source
668
1.61k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 794, False: 11]
7411
805
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
11
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 9]
7412
805
            return r; \
7413
805
        Py_DECREF(r); \
Line
Count
Source
548
9
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
7414
9
    } \
7415
2.58k
    if (do_other) { \
  Branch (7415:9): [True: 1.78k, False: 8]
7416
1.78k
        stack[0] = other; \
7417
1.78k
        stack[1] = self; \
7418
1.78k
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
1.78k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1.78k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1.78k
    _PyRuntime.global_objects.NAME
7419
1.78k
    } \
7420
1.79k
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
8
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
8
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
8
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8
#  define _Py_CAST(type, expr) ((type)(expr))
7421
1.79k
}
typeobject.c:slot_nb_remainder
Line
Count
Source
7382
49
FUNCNAME(PyObject *self, PyObject *other) \
7383
49
{ \
7384
49
    PyObject* stack[2]; \
7385
49
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
49
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
98
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
49
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
49
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 29, False: 20]
7387
49
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
29
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
29
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
29
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 29, False: 0]
7388
49
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
29
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
29
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
29
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 11, False: 18]
7389
49
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
49
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
49
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
49
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 49, False: 0]
7390
49
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
49
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
49
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
49
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 41, False: 8]
7391
41
        PyObject *r; \
7392
41
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 3, False: 38]
  Branch (7392:25): [True: 1, False: 2]
7393
1
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
7394
1
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 1]
7395
0
                return NULL; \
7396
0
            } \
7397
1
            if (ok) { \
  Branch (7397:17): [True: 1, False: 0]
7398
1
                stack[0] = other; \
7399
1
                stack[1] = self; \
7400
1
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
7401
1
                if (r != Py_NotImplemented) \
Line
Count
Source
668
1
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 1, False: 0]
7402
1
                    return r; \
7403
1
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
1
        } \
7407
41
        stack[0] = self; \
7408
40
        stack[1] = other; \
7409
40
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
40
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
40
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
40
    _PyRuntime.global_objects.NAME
7410
40
        if (r != Py_NotImplemented || \
Line
Count
Source
668
80
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 32, False: 8]
7411
40
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
8
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
8
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 6]
7412
40
            return r; \
7413
40
        Py_DECREF(r); \
Line
Count
Source
548
6
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
7414
6
    } \
7415
49
    if (do_other) { \
  Branch (7415:9): [True: 9, False: 5]
7416
9
        stack[0] = other; \
7417
9
        stack[1] = self; \
7418
9
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
9
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
9
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
9
    _PyRuntime.global_objects.NAME
7419
9
    } \
7420
14
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
5
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
5
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
7421
14
}
typeobject.c:slot_nb_divmod
Line
Count
Source
7382
2.59k
FUNCNAME(PyObject *self, PyObject *other) \
7383
2.59k
{ \
7384
2.59k
    PyObject* stack[2]; \
7385
2.59k
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
2.59k
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
5.19k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
2.59k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.59k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 48, False: 2.55k]
7387
2.59k
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
48
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
48
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
48
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 48, False: 0]
7388
2.59k
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
48
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
48
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
48
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 9, False: 39]
7389
2.59k
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
2.59k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.59k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.59k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 2.59k, False: 0]
7390
2.59k
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
2.59k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.59k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.59k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 2.59k, False: 7]
7391
2.59k
        PyObject *r; \
7392
2.59k
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
2
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
2
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 2, False: 2.59k]
  Branch (7392:25): [True: 0, False: 2]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
2.59k
        stack[0] = self; \
7408
2.59k
        stack[1] = other; \
7409
2.59k
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
2.59k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
2.59k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
2.59k
    _PyRuntime.global_objects.NAME
7410
2.59k
        if (r != Py_NotImplemented || \
Line
Count
Source
668
5.18k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 2.58k, False: 5]
7411
2.59k
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
5
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 1, False: 4]
7412
2.59k
            return r; \
7413
2.59k
        Py_DECREF(r); \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7414
4
    } \
7415
2.59k
    if (do_other) { \
  Branch (7415:9): [True: 8, False: 3]
7416
8
        stack[0] = other; \
7417
8
        stack[1] = self; \
7418
8
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
8
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
8
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
8
    _PyRuntime.global_objects.NAME
7419
8
    } \
7420
11
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
3
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
3
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
7421
11
}
typeobject.c:slot_nb_power_binary
Line
Count
Source
7382
117k
FUNCNAME(PyObject *self, PyObject *other) \
7383
117k
{ \
7384
117k
    PyObject* stack[2]; \
7385
117k
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
117k
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
234k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 117k, False: 22]
7387
117k
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
117k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 117k, False: 0]
7388
117k
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
117k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 18, False: 117k]
7389
117k
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
117k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 117k, False: 1]
7390
117k
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
117k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
117k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
117k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 117k, False: 14]
7391
117k
        PyObject *r; \
7392
117k
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 3, False: 117k]
  Branch (7392:25): [True: 0, False: 3]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
117k
        stack[0] = self; \
7408
117k
        stack[1] = other; \
7409
117k
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
117k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
117k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
117k
    _PyRuntime.global_objects.NAME
7410
117k
        if (r != Py_NotImplemented || \
Line
Count
Source
668
234k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 117k, False: 7]
7411
117k
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
7
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
7
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 5]
7412
117k
            return r; \
7413
117k
        Py_DECREF(r); \
Line
Count
Source
548
5
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
7414
5
    } \
7415
117k
    if (do_other) { \
  Branch (7415:9): [True: 16, False: 4]
7416
16
        stack[0] = other; \
7417
16
        stack[1] = self; \
7418
16
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
16
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
16
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
16
    _PyRuntime.global_objects.NAME
7419
16
    } \
7420
20
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7421
20
}
typeobject.c:slot_nb_lshift
Line
Count
Source
7382
11
FUNCNAME(PyObject *self, PyObject *other) \
7383
11
{ \
7384
11
    PyObject* stack[2]; \
7385
11
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
11
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
22
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 9, False: 2]
7387
11
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
9
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 9, False: 0]
7388
11
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
9
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 3, False: 6]
7389
11
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
11
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 11, False: 0]
7390
11
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
11
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 8, False: 3]
7391
8
        PyObject *r; \
7392
8
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 0, False: 8]
  Branch (7392:25): [True: 0, False: 0]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
8
        stack[0] = self; \
7408
8
        stack[1] = other; \
7409
8
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
8
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
8
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
8
    _PyRuntime.global_objects.NAME
7410
8
        if (r != Py_NotImplemented || \
Line
Count
Source
668
16
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 2, False: 6]
7411
8
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
6
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 4]
7412
8
            return r; \
7413
8
        Py_DECREF(r); \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7414
4
    } \
7415
11
    if (do_other) { \
  Branch (7415:9): [True: 3, False: 4]
7416
3
        stack[0] = other; \
7417
3
        stack[1] = self; \
7418
3
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
3
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
3
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
3
    _PyRuntime.global_objects.NAME
7419
3
    } \
7420
7
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7421
7
}
typeobject.c:slot_nb_rshift
Line
Count
Source
7382
12
FUNCNAME(PyObject *self, PyObject *other) \
7383
12
{ \
7384
12
    PyObject* stack[2]; \
7385
12
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
12
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
24
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 10, False: 2]
7387
12
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 10, False: 0]
7388
12
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 4, False: 6]
7389
12
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
12
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 11, False: 1]
7390
12
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
11
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 8, False: 3]
7391
8
        PyObject *r; \
7392
8
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 0, False: 8]
  Branch (7392:25): [True: 0, False: 0]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
8
        stack[0] = self; \
7408
8
        stack[1] = other; \
7409
8
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
8
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
8
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
8
    _PyRuntime.global_objects.NAME
7410
8
        if (r != Py_NotImplemented || \
Line
Count
Source
668
16
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 2, False: 6]
7411
8
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
6
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 4]
7412
8
            return r; \
7413
8
        Py_DECREF(r); \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7414
4
    } \
7415
12
    if (do_other) { \
  Branch (7415:9): [True: 4, False: 4]
7416
4
        stack[0] = other; \
7417
4
        stack[1] = self; \
7418
4
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
4
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
4
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
4
    _PyRuntime.global_objects.NAME
7419
4
    } \
7420
8
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7421
8
}
typeobject.c:slot_nb_and
Line
Count
Source
7382
26.2k
FUNCNAME(PyObject *self, PyObject *other) \
7383
26.2k
{ \
7384
26.2k
    PyObject* stack[2]; \
7385
26.2k
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
26.2k
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
52.4k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
26.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
26.2k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 21.3k, False: 4.89k]
7387
26.2k
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
21.3k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
21.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21.3k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 21.3k, False: 1]
7388
26.2k
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
21.3k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
21.3k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
21.3k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 20.2k, False: 1.02k]
7389
26.2k
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
26.2k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
26.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
26.2k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 26.2k, False: 0]
7390
26.2k
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
26.2k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
26.2k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
26.2k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 5.91k, False: 20.2k]
7391
5.91k
        PyObject *r; \
7392
5.91k
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 1, False: 5.91k]
  Branch (7392:25): [True: 0, False: 1]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
5.91k
        stack[0] = self; \
7408
5.91k
        stack[1] = other; \
7409
5.91k
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
5.91k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
5.91k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
5.91k
    _PyRuntime.global_objects.NAME
7410
5.91k
        if (r != Py_NotImplemented || \
Line
Count
Source
668
11.8k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 5.91k, False: 7]
7411
5.91k
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
7
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
7
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 5]
7412
5.91k
            return r; \
7413
5.91k
        Py_DECREF(r); \
Line
Count
Source
548
5
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
7414
5
    } \
7415
26.2k
    if (do_other) { \
  Branch (7415:9): [True: 20.2k, False: 4]
7416
20.2k
        stack[0] = other; \
7417
20.2k
        stack[1] = self; \
7418
20.2k
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
20.2k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
20.2k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
20.2k
    _PyRuntime.global_objects.NAME
7419
20.2k
    } \
7420
20.2k
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7421
20.2k
}
typeobject.c:slot_nb_xor
Line
Count
Source
7382
224
FUNCNAME(PyObject *self, PyObject *other) \
7383
224
{ \
7384
224
    PyObject* stack[2]; \
7385
224
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
224
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
448
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
224
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
224
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 166, False: 58]
7387
224
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
166
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
166
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
166
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 165, False: 1]
7388
224
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
165
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
165
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
165
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 80, False: 85]
7389
224
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
224
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
224
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
224
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 224, False: 0]
7390
224
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
224
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
224
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
224
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 145, False: 79]
7391
145
        PyObject *r; \
7392
145
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 1, False: 144]
  Branch (7392:25): [True: 0, False: 1]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
145
        stack[0] = self; \
7408
145
        stack[1] = other; \
7409
145
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
145
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
145
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
145
    _PyRuntime.global_objects.NAME
7410
145
        if (r != Py_NotImplemented || \
Line
Count
Source
668
290
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 138, False: 7]
7411
145
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
7
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
7
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 5]
7412
145
            return r; \
7413
145
        Py_DECREF(r); \
Line
Count
Source
548
5
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
7414
5
    } \
7415
224
    if (do_other) { \
  Branch (7415:9): [True: 80, False: 4]
7416
80
        stack[0] = other; \
7417
80
        stack[1] = self; \
7418
80
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
80
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
80
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
80
    _PyRuntime.global_objects.NAME
7419
80
    } \
7420
84
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7421
84
}
typeobject.c:slot_nb_or
Line
Count
Source
7382
6.28k
FUNCNAME(PyObject *self, PyObject *other) \
7383
6.28k
{ \
7384
6.28k
    PyObject* stack[2]; \
7385
6.28k
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
6.28k
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
12.5k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
6.28k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6.28k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 1.24k, False: 5.03k]
7387
6.28k
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
1.24k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1.24k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.24k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 1.24k, False: 4]
7388
6.28k
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
1.24k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1.24k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.24k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 886, False: 359]
7389
6.28k
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
6.28k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
6.28k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6.28k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 6.28k, False: 0]
7390
6.28k
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
6.28k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
6.28k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6.28k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 5.41k, False: 873]
7391
5.41k
        PyObject *r; \
7392
5.41k
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
13
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
13
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
13
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
13
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 13, False: 5.39k]
  Branch (7392:25): [True: 7, False: 6]
7393
7
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
7
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
7
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
7
    _PyRuntime.global_objects.NAME
7394
7
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 7]
7395
0
                return NULL; \
7396
0
            } \
7397
7
            if (ok) { \
  Branch (7397:17): [True: 1, False: 6]
7398
1
                stack[0] = other; \
7399
1
                stack[1] = self; \
7400
1
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
7401
1
                if (r != Py_NotImplemented) \
Line
Count
Source
668
1
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 1, False: 0]
7402
1
                    return r; \
7403
1
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
7
        } \
7407
5.41k
        stack[0] = self; \
7408
5.41k
        stack[1] = other; \
7409
5.41k
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
5.41k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
5.41k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
5.41k
    _PyRuntime.global_objects.NAME
7410
5.41k
        if (r != Py_NotImplemented || \
Line
Count
Source
668
10.8k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 5.39k, False: 16]
7411
5.41k
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
16
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
16
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 14]
7412
5.41k
            return r; \
7413
5.41k
        Py_DECREF(r); \
Line
Count
Source
548
14
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
14
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
14
#  define _Py_CAST(type, expr) ((type)(expr))
7414
14
    } \
7415
6.28k
    if (do_other) { \
  Branch (7415:9): [True: 874, False: 13]
7416
874
        stack[0] = other; \
7417
874
        stack[1] = self; \
7418
874
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
874
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
874
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
874
    _PyRuntime.global_objects.NAME
7419
874
    } \
7420
887
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
13
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
13
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
13
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13
#  define _Py_CAST(type, expr) ((type)(expr))
7421
887
}
typeobject.c:slot_nb_floor_divide
Line
Count
Source
7382
1.74k
FUNCNAME(PyObject *self, PyObject *other) \
7383
1.74k
{ \
7384
1.74k
    PyObject* stack[2]; \
7385
1.74k
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
1.74k
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
3.48k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
1.74k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.74k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 66, False: 1.67k]
7387
1.74k
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
66
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
66
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
66
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 66, False: 0]
7388
1.74k
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
66
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
66
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
66
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 35, False: 31]
7389
1.74k
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
1.74k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1.74k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.74k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 1.74k, False: 0]
7390
1.74k
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
1.74k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1.74k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.74k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 1.71k, False: 25]
7391
1.71k
        PyObject *r; \
7392
1.71k
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
10
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 10, False: 1.70k]
  Branch (7392:25): [True: 2, False: 8]
7393
2
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
2
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
2
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
2
    _PyRuntime.global_objects.NAME
7394
2
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 2]
7395
0
                return NULL; \
7396
0
            } \
7397
2
            if (ok) { \
  Branch (7397:17): [True: 1, False: 1]
7398
1
                stack[0] = other; \
7399
1
                stack[1] = self; \
7400
1
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
1
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1
    _PyRuntime.global_objects.NAME
7401
1
                if (r != Py_NotImplemented) \
Line
Count
Source
668
1
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 1, False: 0]
7402
1
                    return r; \
7403
1
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
2
        } \
7407
1.71k
        stack[0] = self; \
7408
1.71k
        stack[1] = other; \
7409
1.71k
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
1.71k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1.71k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1.71k
    _PyRuntime.global_objects.NAME
7410
1.71k
        if (r != Py_NotImplemented || \
Line
Count
Source
668
3.43k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 1.70k, False: 11]
7411
1.71k
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
11
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
11
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
11
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 9]
7412
1.71k
            return r; \
7413
1.71k
        Py_DECREF(r); \
Line
Count
Source
548
9
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
9
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9
#  define _Py_CAST(type, expr) ((type)(expr))
7414
9
    } \
7415
1.74k
    if (do_other) { \
  Branch (7415:9): [True: 26, False: 8]
7416
26
        stack[0] = other; \
7417
26
        stack[1] = self; \
7418
26
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
26
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
26
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
26
    _PyRuntime.global_objects.NAME
7419
26
    } \
7420
34
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
8
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
8
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
8
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8
#  define _Py_CAST(type, expr) ((type)(expr))
7421
34
}
typeobject.c:slot_nb_true_divide
Line
Count
Source
7382
163k
FUNCNAME(PyObject *self, PyObject *other) \
7383
163k
{ \
7384
163k
    PyObject* stack[2]; \
7385
163k
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
163k
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
327k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
163k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
163k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 141k, False: 21.8k]
7387
163k
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
141k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
141k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
141k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 141k, False: 0]
7388
163k
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
141k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
141k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
141k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 207, False: 141k]
7389
163k
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
163k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
163k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
163k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 163k, False: 0]
7390
163k
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
163k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
163k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
163k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 163k, False: 179]
7391
163k
        PyObject *r; \
7392
163k
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
28
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
28
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
28
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
28
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
28
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
28
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 28, False: 163k]
  Branch (7392:25): [True: 0, False: 28]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
163k
        stack[0] = self; \
7408
163k
        stack[1] = other; \
7409
163k
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
163k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
163k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
163k
    _PyRuntime.global_objects.NAME
7410
163k
        if (r != Py_NotImplemented || \
Line
Count
Source
668
326k
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 163k, False: 10]
7411
163k
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
10
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
10
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 8]
7412
163k
            return r; \
7413
163k
        Py_DECREF(r); \
Line
Count
Source
548
8
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
8
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8
#  define _Py_CAST(type, expr) ((type)(expr))
7414
8
    } \
7415
163k
    if (do_other) { \
  Branch (7415:9): [True: 181, False: 6]
7416
181
        stack[0] = other; \
7417
181
        stack[1] = self; \
7418
181
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
181
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
181
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
181
    _PyRuntime.global_objects.NAME
7419
181
    } \
7420
187
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
6
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
6
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
7421
187
}
typeobject.c:slot_nb_matrix_multiply
Line
Count
Source
7382
19
FUNCNAME(PyObject *self, PyObject *other) \
7383
19
{ \
7384
19
    PyObject* stack[2]; \
7385
19
    PyThreadState *tstate = _PyThreadState_GET(); \
7386
19
    int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Line
Count
Source
155
38
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
19
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
19
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7386:20): [True: 16, False: 3]
7387
19
        Py_TYPE(other)->tp_as_number != NULL && \
Line
Count
Source
138
16
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7387:9): [True: 16, False: 0]
7388
19
        Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Line
Count
Source
138
16
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
16
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7388:9): [True: 5, False: 11]
7389
19
    if (Py_TYPE(self)->tp_as_number != NULL && \
Line
Count
Source
138
19
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
19
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
19
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7389:9): [True: 19, False: 0]
7390
19
        Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
Line
Count
Source
138
19
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
19
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
19
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7390:9): [True: 14, False: 5]
7391
14
        PyObject *r; \
7392
14
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
        if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7392:13): [True: 0, False: 14]
  Branch (7392:25): [True: 0, False: 0]
7393
0
            int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7394
0
            if (ok < 0) { \
  Branch (7394:17): [True: 0, False: 0]
7395
0
                return NULL; \
7396
0
            } \
7397
0
            if (ok) { \
  Branch (7397:17): [True: 0, False: 0]
7398
0
                stack[0] = other; \
7399
0
                stack[1] = self; \
7400
0
                r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7401
0
                if (r != Py_NotImplemented) \
Line
Count
Source
668
0
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7401:21): [True: 0, False: 0]
7402
0
                    return r; \
7403
0
                Py_DECREF(r); \
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7404
0
                do_other = 0; \
7405
0
            } \
7406
0
        } \
7407
14
        stack[0] = self; \
7408
14
        stack[1] = other; \
7409
14
        r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
Line
Count
Source
374
14
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
14
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
14
    _PyRuntime.global_objects.NAME
7410
14
        if (r != Py_NotImplemented || \
Line
Count
Source
668
28
#define Py_NotImplemented (&_Py_NotImplementedStruct)
  Branch (7410:13): [True: 8, False: 6]
7411
14
            Py_IS_TYPE(other, Py_TYPE(self))) \
Line
Count
Source
155
6
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 2, False: 4]
7412
14
            return r; \
7413
14
        Py_DECREF(r); \
Line
Count
Source
548
4
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7414
4
    } \
7415
19
    if (do_other) { \
  Branch (7415:9): [True: 5, False: 4]
7416
5
        stack[0] = other; \
7417
5
        stack[1] = self; \
7418
5
        return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
Line
Count
Source
374
5
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
5
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
5
    _PyRuntime.global_objects.NAME
7419
5
    } \
7420
9
    Py_RETURN_NOTIMPLEMENTED; \
Line
Count
Source
671
4
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
4
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
4
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
4
#  define _Py_CAST(type, expr) ((type)(expr))
7421
9
}
7422
7423
#define SLOT1BIN(FUNCNAME, SLOTNAME, DUNDER, RDUNDER) \
7424
    SLOT1BINFULL(FUNCNAME, FUNCNAME, SLOTNAME, DUNDER, RDUNDER)
7425
7426
static Py_ssize_t
7427
slot_sq_length(PyObject *self)
7428
967k
{
7429
967k
    PyObject* stack[1] = {self};
7430
967k
    PyObject *res = vectorcall_method(&_Py_ID(__len__), stack, 1);
Line
Count
Source
374
967k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
967k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
967k
    _PyRuntime.global_objects.NAME
7431
967k
    Py_ssize_t len;
7432
7433
967k
    if (res == NULL)
  Branch (7433:9): [True: 11, False: 967k]
7434
11
        return -1;
7435
7436
967k
    Py_SETREF(res, _PyNumber_Index(res));
Line
Count
Source
332
967k
    do {                                        \
333
967k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
967k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
967k
#  define _Py_CAST(type, expr) ((type)(expr))
334
967k
        (op) = (op2);                           \
335
967k
        Py_DECREF(_py_tmp);                     \
Line
Count
Source
548
967k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
967k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
967k
#  define _Py_CAST(type, expr) ((type)(expr))
336
967k
    } while (0)
  Branch (336:14): [Folded - Ignored]
7437
967k
    if (res == NULL)
  Branch (7437:9): [True: 4, False: 967k]
7438
4
        return -1;
7439
7440
967k
    assert(PyLong_Check(res));
7441
967k
    if (Py_SIZE(res) < 0) {
Line
Count
Source
147
967k
#  define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
Line
Count
Source
109
967k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
967k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7441:9): [True: 5, False: 967k]
7442
5
        Py_DECREF(res);
Line
Count
Source
548
5
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
7443
5
        PyErr_SetString(PyExc_ValueError,
7444
5
                        "__len__() should return >= 0");
7445
5
        return -1;
7446
5
    }
7447
7448
967k
    len = PyNumber_AsSsize_t(res, PyExc_OverflowError);
7449
967k
    assert(len >= 0 || PyErr_ExceptionMatches(PyExc_OverflowError));
7450
967k
    Py_DECREF(res);
Line
Count
Source
548
967k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
967k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
967k
#  define _Py_CAST(type, expr) ((type)(expr))
7451
967k
    return len;
7452
967k
}
7453
7454
static PyObject *
7455
slot_sq_item(PyObject *self, Py_ssize_t i)
7456
246k
{
7457
246k
    PyObject *ival = PyLong_FromSsize_t(i);
7458
246k
    if (ival == NULL) {
  Branch (7458:9): [True: 0, False: 246k]
7459
0
        return NULL;
7460
0
    }
7461
246k
    PyObject *stack[2] = {self, ival};
7462
246k
    PyObject *retval = vectorcall_method(&_Py_ID(__getitem__), stack, 2);
Line
Count
Source
374
246k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
246k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
246k
    _PyRuntime.global_objects.NAME
7463
246k
    Py_DECREF(ival);
Line
Count
Source
548
246k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
246k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
246k
#  define _Py_CAST(type, expr) ((type)(expr))
7464
246k
    return retval;
7465
246k
}
7466
7467
static int
7468
slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value)
7469
863
{
7470
863
    PyObject *stack[3];
7471
863
    PyObject *res;
7472
863
    PyObject *index_obj;
7473
7474
863
    index_obj = PyLong_FromSsize_t(index);
7475
863
    if (index_obj == NULL) {
  Branch (7475:9): [True: 0, False: 863]
7476
0
        return -1;
7477
0
    }
7478
7479
863
    stack[0] = self;
7480
863
    stack[1] = index_obj;
7481
863
    if (value == NULL) {
  Branch (7481:9): [True: 0, False: 863]
7482
0
        res = vectorcall_method(&_Py_ID(__delitem__), stack, 2);
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7483
0
    }
7484
863
    else {
7485
863
        stack[2] = value;
7486
863
        res = vectorcall_method(&_Py_ID(__setitem__), stack, 3);
Line
Count
Source
374
863
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
863
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
863
    _PyRuntime.global_objects.NAME
7487
863
    }
7488
863
    Py_DECREF(index_obj);
Line
Count
Source
548
863
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
863
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
863
#  define _Py_CAST(type, expr) ((type)(expr))
7489
7490
863
    if (res == NULL) {
  Branch (7490:9): [True: 15, False: 848]
7491
15
        return -1;
7492
15
    }
7493
848
    Py_DECREF(res);
Line
Count
Source
548
848
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
848
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
848
#  define _Py_CAST(type, expr) ((type)(expr))
7494
848
    return 0;
7495
863
}
7496
7497
static int
7498
slot_sq_contains(PyObject *self, PyObject *value)
7499
385k
{
7500
385k
    PyThreadState *tstate = _PyThreadState_GET();
7501
385k
    PyObject *func, *res;
7502
385k
    int result = -1, unbound;
7503
7504
385k
    func = lookup_maybe_method(self, &_Py_ID(__contains__), &unbound);
Line
Count
Source
374
385k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
385k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
385k
    _PyRuntime.global_objects.NAME
7505
385k
    if (func == Py_None) {
Line
Count
Source
654
385k
#define Py_None (&_Py_NoneStruct)
  Branch (7505:9): [True: 1, False: 385k]
7506
1
        Py_DECREF(func);
Line
Count
Source
548
1
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
7507
1
        PyErr_Format(PyExc_TypeError,
7508
1
                     "'%.200s' object is not a container",
7509
1
                     Py_TYPE(self)->tp_name);
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
7510
1
        return -1;
7511
1
    }
7512
385k
    if (func != NULL) {
  Branch (7512:9): [True: 385k, False: 0]
7513
385k
        PyObject *args[2] = {self, value};
7514
385k
        res = vectorcall_unbound(tstate, unbound, func, args, 2);
7515
385k
        Py_DECREF(func);
Line
Count
Source
548
385k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
385k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
385k
#  define _Py_CAST(type, expr) ((type)(expr))
7516
385k
        if (res != NULL) {
  Branch (7516:13): [True: 385k, False: 3]
7517
385k
            result = PyObject_IsTrue(res);
7518
385k
            Py_DECREF(res);
Line
Count
Source
548
385k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
385k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
385k
#  define _Py_CAST(type, expr) ((type)(expr))
7519
385k
        }
7520
385k
    }
7521
0
    else if (! PyErr_Occurred()) {
  Branch (7521:14): [True: 0, False: 0]
7522
        /* Possible results: -1 and 1 */
7523
0
        result = (int)_PySequence_IterSearch(self, value,
7524
0
                                         PY_ITERSEARCH_CONTAINS);
Line
Count
Source
183
0
#define PY_ITERSEARCH_CONTAINS 3
7525
0
    }
7526
385k
    return result;
7527
385k
}
7528
7529
#define slot_mp_length slot_sq_length
7530
7531
SLOT1(slot_mp_subscript, __getitem__, PyObject *)
7532
7533
static int
7534
slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value)
7535
985k
{
7536
985k
    PyObject *stack[3];
7537
985k
    PyObject *res;
7538
7539
985k
    stack[0] = self;
7540
985k
    stack[1] = key;
7541
985k
    if (value == NULL) {
  Branch (7541:9): [True: 49.0k, False: 936k]
7542
49.0k
        res = vectorcall_method(&_Py_ID(__delitem__), stack, 2);
Line
Count
Source
374
49.0k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
49.0k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
49.0k
    _PyRuntime.global_objects.NAME
7543
49.0k
    }
7544
936k
    else {
7545
936k
        stack[2] = value;
7546
936k
        res = vectorcall_method(&_Py_ID(__setitem__), stack, 3);
Line
Count
Source
374
936k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
936k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
936k
    _PyRuntime.global_objects.NAME
7547
936k
    }
7548
7549
985k
    if (res == NULL)
  Branch (7549:9): [True: 251, False: 985k]
7550
251
        return -1;
7551
985k
    Py_DECREF(res);
Line
Count
Source
548
985k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
985k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
985k
#  define _Py_CAST(type, expr) ((type)(expr))
7552
985k
    return 0;
7553
985k
}
7554
7555
SLOT1BIN(slot_nb_add, nb_add, __add__, __radd__)
7556
SLOT1BIN(slot_nb_subtract, nb_subtract, __sub__, __rsub__)
7557
SLOT1BIN(slot_nb_multiply, nb_multiply, __mul__, __rmul__)
7558
SLOT1BIN(slot_nb_matrix_multiply, nb_matrix_multiply, __matmul__, __rmatmul__)
7559
SLOT1BIN(slot_nb_remainder, nb_remainder, __mod__, __rmod__)
7560
SLOT1BIN(slot_nb_divmod, nb_divmod, __divmod__, __rdivmod__)
7561
7562
static PyObject *slot_nb_power(PyObject *, PyObject *, PyObject *);
7563
7564
SLOT1BINFULL(slot_nb_power_binary, slot_nb_power, nb_power, __pow__, __rpow__)
7565
7566
static PyObject *
7567
slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus)
7568
117k
{
7569
117k
    if (modulus == Py_None)
Line
Count
Source
654
117k
#define Py_None (&_Py_NoneStruct)
  Branch (7569:9): [True: 117k, False: 3]
7570
117k
        return slot_nb_power_binary(self, other);
7571
    /* Three-arg power doesn't use __rpow__.  But ternary_op
7572
       can call this when the second argument's type uses
7573
       slot_nb_power, so check before calling self.__pow__. */
7574
3
    if (Py_TYPE(self)->tp_as_number != NULL &&
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7574:9): [True: 3, False: 0]
7575
3
        Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) {
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (7575:9): [True: 2, False: 1]
7576
2
        PyObject* stack[3] = {self, other, modulus};
7577
2
        return vectorcall_method(&_Py_ID(__pow__), stack, 3);
Line
Count
Source
374
2
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
2
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
2
    _PyRuntime.global_objects.NAME
7578
2
    }
7579
3
    Py_RETURN_NOTIMPLEMENTED;
Line
Count
Source
671
1
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
1
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
7580
3
}
7581
7582
SLOT0(slot_nb_negative, __neg__)
7583
SLOT0(slot_nb_positive, __pos__)
7584
SLOT0(slot_nb_absolute, __abs__)
7585
7586
static int
7587
slot_nb_bool(PyObject *self)
7588
165k
{
7589
165k
    PyObject *func, *value;
7590
165k
    int result, unbound;
7591
165k
    int using_len = 0;
7592
7593
165k
    func = lookup_maybe_method(self, &_Py_ID(__bool__), &unbound);
Line
Count
Source
374
165k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
165k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
165k
    _PyRuntime.global_objects.NAME
7594
165k
    if (func == NULL) {
  Branch (7594:9): [True: 0, False: 165k]
7595
0
        if (PyErr_Occurred()) {
  Branch (7595:13): [True: 0, False: 0]
7596
0
            return -1;
7597
0
        }
7598
7599
0
        func = lookup_maybe_method(self, &_Py_ID(__len__), &unbound);
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7600
0
        if (func == NULL) {
  Branch (7600:13): [True: 0, False: 0]
7601
0
            if (PyErr_Occurred()) {
  Branch (7601:17): [True: 0, False: 0]
7602
0
                return -1;
7603
0
            }
7604
0
            return 1;
7605
0
        }
7606
0
        using_len = 1;
7607
0
    }
7608
7609
165k
    value = call_unbound_noarg(unbound, func, self);
7610
165k
    if (value == NULL) {
  Branch (7610:9): [True: 85, False: 165k]
7611
85
        goto error;
7612
85
    }
7613
7614
165k
    if (using_len) {
  Branch (7614:9): [True: 0, False: 165k]
7615
        /* bool type enforced by slot_nb_len */
7616
0
        result = PyObject_IsTrue(value);
7617
0
    }
7618
165k
    else if (PyBool_Check(value)) {
Line
Count
Source
12
165k
#define PyBool_Check(x) Py_IS_TYPE((x), &PyBool_Type)
Line
Count
Source
155
165k
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
165k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
165k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 165k, False: 5]
7619
165k
        result = PyObject_IsTrue(value);
7620
165k
    }
7621
5
    else {
7622
5
        PyErr_Format(PyExc_TypeError,
7623
5
                     "__bool__ should return "
7624
5
                     "bool, returned %s",
7625
5
                     Py_TYPE(value)->tp_name);
Line
Count
Source
138
5
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
5
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
5
#  define _Py_CAST(type, expr) ((type)(expr))
7626
5
        result = -1;
7627
5
    }
7628
7629
165k
    Py_DECREF(value);
Line
Count
Source
548
165k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
165k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
165k
#  define _Py_CAST(type, expr) ((type)(expr))
7630
165k
    Py_DECREF(func);
Line
Count
Source
548
165k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
165k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
165k
#  define _Py_CAST(type, expr) ((type)(expr))
7631
165k
    return result;
7632
7633
85
error:
7634
85
    Py_DECREF(func);
Line
Count
Source
548
85
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
85
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
85
#  define _Py_CAST(type, expr) ((type)(expr))
7635
85
    return -1;
7636
165k
}
7637
7638
7639
static PyObject *
7640
slot_nb_index(PyObject *self)
7641
3.33k
{
7642
3.33k
    PyObject *stack[1] = {self};
7643
3.33k
    return vectorcall_method(&_Py_ID(__index__), stack, 1);
Line
Count
Source
374
3.33k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
3.33k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
3.33k
    _PyRuntime.global_objects.NAME
7644
3.33k
}
7645
7646
7647
SLOT0(slot_nb_invert, __invert__)
7648
SLOT1BIN(slot_nb_lshift, nb_lshift, __lshift__, __rlshift__)
7649
SLOT1BIN(slot_nb_rshift, nb_rshift, __rshift__, __rrshift__)
7650
SLOT1BIN(slot_nb_and, nb_and, __and__, __rand__)
7651
SLOT1BIN(slot_nb_xor, nb_xor, __xor__, __rxor__)
7652
SLOT1BIN(slot_nb_or, nb_or, __or__, __ror__)
7653
7654
SLOT0(slot_nb_int, __int__)
7655
SLOT0(slot_nb_float, __float__)
7656
SLOT1(slot_nb_inplace_add, __iadd__, PyObject *)
7657
SLOT1(slot_nb_inplace_subtract, __isub__, PyObject *)
7658
SLOT1(slot_nb_inplace_multiply, __imul__, PyObject *)
7659
SLOT1(slot_nb_inplace_matrix_multiply, __imatmul__, PyObject *)
7660
SLOT1(slot_nb_inplace_remainder, __imod__, PyObject *)
7661
/* Can't use SLOT1 here, because nb_inplace_power is ternary */
7662
static PyObject *
7663
slot_nb_inplace_power(PyObject *self, PyObject * arg1, PyObject *arg2)
7664
9
{
7665
9
    PyObject *stack[2] = {self, arg1};
7666
9
    return vectorcall_method(&_Py_ID(__ipow__), stack, 2);
Line
Count
Source
374
9
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
9
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
9
    _PyRuntime.global_objects.NAME
7667
9
}
7668
SLOT1(slot_nb_inplace_lshift, __ilshift__, PyObject *)
7669
SLOT1(slot_nb_inplace_rshift, __irshift__, PyObject *)
7670
SLOT1(slot_nb_inplace_and, __iand__, PyObject *)
7671
SLOT1(slot_nb_inplace_xor, __ixor__, PyObject *)
7672
SLOT1(slot_nb_inplace_or, __ior__, PyObject *)
7673
SLOT1BIN(slot_nb_floor_divide, nb_floor_divide,
7674
         __floordiv__, __rfloordiv__)
7675
SLOT1BIN(slot_nb_true_divide, nb_true_divide, __truediv__, __rtruediv__)
7676
SLOT1(slot_nb_inplace_floor_divide, __ifloordiv__, PyObject *)
7677
SLOT1(slot_nb_inplace_true_divide, __itruediv__, PyObject *)
7678
7679
static PyObject *
7680
slot_tp_repr(PyObject *self)
7681
23.7k
{
7682
23.7k
    PyObject *func, *res;
7683
23.7k
    int unbound;
7684
7685
23.7k
    func = lookup_maybe_method(self, &_Py_ID(__repr__), &unbound);
Line
Count
Source
374
23.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
23.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
23.7k
    _PyRuntime.global_objects.NAME
7686
23.7k
    if (func != NULL) {
  Branch (7686:9): [True: 23.7k, False: 0]
7687
23.7k
        res = call_unbound_noarg(unbound, func, self);
7688
23.7k
        Py_DECREF(func);
Line
Count
Source
548
23.7k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
23.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
23.7k
#  define _Py_CAST(type, expr) ((type)(expr))
7689
23.7k
        return res;
7690
23.7k
    }
7691
0
    PyErr_Clear();
7692
0
    return PyUnicode_FromFormat("<%s object at %p>",
7693
0
                               Py_TYPE(self)->tp_name, self);
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7694
23.7k
}
7695
7696
SLOT0(slot_tp_str, __str__)
7697
7698
static Py_hash_t
7699
slot_tp_hash(PyObject *self)
7700
1.31M
{
7701
1.31M
    PyObject *func, *res;
7702
1.31M
    Py_ssize_t h;
7703
1.31M
    int unbound;
7704
7705
1.31M
    func = lookup_maybe_method(self, &_Py_ID(__hash__), &unbound);
Line
Count
Source
374
1.31M
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1.31M
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1.31M
    _PyRuntime.global_objects.NAME
7706
7707
1.31M
    if (func == Py_None) {
Line
Count
Source
654
1.31M
#define Py_None (&_Py_NoneStruct)
  Branch (7707:9): [True: 0, False: 1.31M]
7708
0
        Py_DECREF(func);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7709
0
        func = NULL;
7710
0
    }
7711
7712
1.31M
    if (func == NULL) {
  Branch (7712:9): [True: 0, False: 1.31M]
7713
0
        return PyObject_HashNotImplemented(self);
7714
0
    }
7715
7716
1.31M
    res = call_unbound_noarg(unbound, func, self);
7717
1.31M
    Py_DECREF(func);
Line
Count
Source
548
1.31M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1.31M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.31M
#  define _Py_CAST(type, expr) ((type)(expr))
7718
1.31M
    if (res == NULL)
  Branch (7718:9): [True: 452, False: 1.31M]
7719
452
        return -1;
7720
7721
1.31M
    if (!PyLong_Check(res)) {
Line
Count
Source
13
1.31M
        PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
Line
Count
Source
782
1.31M
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (7721:9): [True: 0, False: 1.31M]
7722
0
        PyErr_SetString(PyExc_TypeError,
7723
0
                        "__hash__ method should return an integer");
7724
0
        return -1;
7725
0
    }
7726
    /* Transform the PyLong `res` to a Py_hash_t `h`.  For an existing
7727
       hashable Python object x, hash(x) will always lie within the range of
7728
       Py_hash_t.  Therefore our transformation must preserve values that
7729
       already lie within this range, to ensure that if x.__hash__() returns
7730
       hash(y) then hash(x) == hash(y). */
7731
1.31M
    h = PyLong_AsSsize_t(res);
7732
1.31M
    if (h == -1 && PyErr_Occurred()) {
  Branch (7732:9): [True: 1, False: 1.31M]
  Branch (7732:20): [True: 1, False: 0]
7733
        /* res was not within the range of a Py_hash_t, so we're free to
7734
           use any sufficiently bit-mixing transformation;
7735
           long.__hash__ will do nicely. */
7736
1
        PyErr_Clear();
7737
1
        h = PyLong_Type.tp_hash(res);
7738
1
    }
7739
    /* -1 is reserved for errors. */
7740
1.31M
    if (h == -1)
  Branch (7740:9): [True: 0, False: 1.31M]
7741
0
        h = -2;
7742
1.31M
    Py_DECREF(res);
Line
Count
Source
548
1.31M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1.31M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.31M
#  define _Py_CAST(type, expr) ((type)(expr))
7743
1.31M
    return h;
7744
1.31M
}
7745
7746
static PyObject *
7747
slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds)
7748
1.72M
{
7749
1.72M
    PyThreadState *tstate = _PyThreadState_GET();
7750
1.72M
    int unbound;
7751
7752
1.72M
    PyObject *meth = lookup_method(self, &_Py_ID(__call__), &unbound);
Line
Count
Source
374
1.72M
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
1.72M
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
1.72M
    _PyRuntime.global_objects.NAME
7753
1.72M
    if (meth == NULL) {
  Branch (7753:9): [True: 0, False: 1.72M]
7754
0
        return NULL;
7755
0
    }
7756
7757
1.72M
    PyObject *res;
7758
1.72M
    if (unbound) {
  Branch (7758:9): [True: 1.72M, False: 1.96k]
7759
1.72M
        res = _PyObject_Call_Prepend(tstate, meth, self, args, kwds);
7760
1.72M
    }
7761
1.96k
    else {
7762
1.96k
        res = _PyObject_Call(tstate, meth, args, kwds);
7763
1.96k
    }
7764
7765
1.72M
    Py_DECREF(meth);
Line
Count
Source
548
1.72M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1.72M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.72M
#  define _Py_CAST(type, expr) ((type)(expr))
7766
1.72M
    return res;
7767
1.72M
}
7768
7769
/* There are two slot dispatch functions for tp_getattro.
7770
7771
   - slot_tp_getattro() is used when __getattribute__ is overridden
7772
     but no __getattr__ hook is present;
7773
7774
   - slot_tp_getattr_hook() is used when a __getattr__ hook is present.
7775
7776
   The code in update_one_slot() always installs slot_tp_getattr_hook(); this
7777
   detects the absence of __getattr__ and then installs the simpler slot if
7778
   necessary. */
7779
7780
static PyObject *
7781
slot_tp_getattro(PyObject *self, PyObject *name)
7782
10.4k
{
7783
10.4k
    PyObject *stack[2] = {self, name};
7784
10.4k
    return vectorcall_method(&_Py_ID(__getattribute__), stack, 2);
Line
Count
Source
374
10.4k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
10.4k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
10.4k
    _PyRuntime.global_objects.NAME
7785
10.4k
}
7786
7787
static inline PyObject *
7788
call_attribute(PyObject *self, PyObject *attr, PyObject *name)
7789
524k
{
7790
524k
    PyObject *res, *descr = NULL;
7791
7792
524k
    if (_PyType_HasFeature(Py_TYPE(attr), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
Line
Count
Source
138
524k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
524k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
524k
#  define _Py_CAST(type, expr) ((type)(expr))
    if (_PyType_HasFeature(Py_TYPE(attr), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
Line
Count
Source
404
524k
#define Py_TPFLAGS_METHOD_DESCRIPTOR (1UL << 17)
  Branch (7792:9): [True: 524k, False: 3]
7793
524k
        PyObject *args[] = { self, name };
7794
524k
        res = PyObject_Vectorcall(attr, args, 2, NULL);
7795
524k
        return res;
7796
524k
    }
7797
7798
3
    descrgetfunc f = Py_TYPE(attr)->tp_descr_get;
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
7799
7800
3
    if (f != NULL) {
  Branch (7800:9): [True: 3, False: 0]
7801
3
        descr = f(attr, self, (PyObject *)(Py_TYPE(self)));
Line
Count
Source
138
3
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
7802
3
        if (descr == NULL)
  Branch (7802:13): [True: 0, False: 3]
7803
0
            return NULL;
7804
3
        else
7805
3
            attr = descr;
7806
3
    }
7807
3
    res = PyObject_CallOneArg(attr, name);
7808
3
    Py_XDECREF(descr);
Line
Count
Source
613
3
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
3
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3
#  define _Py_CAST(type, expr) ((type)(expr))
7809
3
    return res;
7810
3
}
7811
7812
static PyObject *
7813
slot_tp_getattr_hook(PyObject *self, PyObject *name)
7814
7.33M
{
7815
7.33M
    PyTypeObject *tp = Py_TYPE(self);
Line
Count
Source
138
7.33M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
7.33M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7.33M
#  define _Py_CAST(type, expr) ((type)(expr))
7816
7.33M
    PyObject *getattr, *getattribute, *res;
7817
7818
    /* speed hack: we could use lookup_maybe, but that would resolve the
7819
       method fully for each attribute lookup for classes with
7820
       __getattr__, even when the attribute is present. So we use
7821
       _PyType_Lookup and create the method only when needed, with
7822
       call_attribute. */
7823
7.33M
    getattr = _PyType_Lookup(tp, &_Py_ID(__getattr__));
Line
Count
Source
374
7.33M
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
7.33M
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
7.33M
    _PyRuntime.global_objects.NAME
7824
7.33M
    if (getattr == NULL) {
  Branch (7824:9): [True: 26, False: 7.33M]
7825
        /* No __getattr__ hook: use a simpler dispatcher */
7826
26
        tp->tp_getattro = slot_tp_getattro;
7827
26
        return slot_tp_getattro(self, name);
7828
26
    }
7829
7.33M
    Py_INCREF(getattr);
Line
Count
Source
512
7.33M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
7.33M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7.33M
#  define _Py_CAST(type, expr) ((type)(expr))
7830
    /* speed hack: we could use lookup_maybe, but that would resolve the
7831
       method fully for each attribute lookup for classes with
7832
       __getattr__, even when self has the default __getattribute__
7833
       method. So we use _PyType_Lookup and create the method only when
7834
       needed, with call_attribute. */
7835
7.33M
    getattribute = _PyType_Lookup(tp, &_Py_ID(__getattribute__));
Line
Count
Source
374
7.33M
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
7.33M
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
7.33M
    _PyRuntime.global_objects.NAME
7836
7.33M
    if (getattribute == NULL ||
  Branch (7836:9): [True: 0, False: 7.33M]
7837
7.33M
        (Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) &&
Line
Count
Source
155
14.6M
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
7.33M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7.33M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 7.32M, False: 10.8k]
7838
7.33M
         ((PyWrapperDescrObject *)getattribute)->d_wrapped ==
  Branch (7838:10): [True: 6.89M, False: 430k]
7839
7.32M
         (void *)PyObject_GenericGetAttr))
7840
6.89M
        res = PyObject_GenericGetAttr(self, name);
7841
441k
    else {
7842
441k
        Py_INCREF(getattribute);
Line
Count
Source
512
441k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
441k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
441k
#  define _Py_CAST(type, expr) ((type)(expr))
7843
441k
        res = call_attribute(self, getattribute, name);
7844
441k
        Py_DECREF(getattribute);
Line
Count
Source
548
441k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
441k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
441k
#  define _Py_CAST(type, expr) ((type)(expr))
7845
441k
    }
7846
7.33M
    if (res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
  Branch (7846:9): [True: 82.7k, False: 7.25M]
  Branch (7846:24): [True: 82.7k, False: 0]
7847
82.7k
        PyErr_Clear();
7848
82.7k
        res = call_attribute(self, getattr, name);
7849
82.7k
    }
7850
7.33M
    Py_DECREF(getattr);
Line
Count
Source
548
7.33M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
7.33M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7.33M
#  define _Py_CAST(type, expr) ((type)(expr))
7851
7.33M
    return res;
7852
7.33M
}
7853
7854
static int
7855
slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value)
7856
508k
{
7857
508k
    PyObject *stack[3];
7858
508k
    PyObject *res;
7859
7860
508k
    stack[0] = self;
7861
508k
    stack[1] = name;
7862
508k
    if (value == NULL) {
  Branch (7862:9): [True: 75.8k, False: 432k]
7863
75.8k
        res = vectorcall_method(&_Py_ID(__delattr__), stack, 2);
Line
Count
Source
374
75.8k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
75.8k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
75.8k
    _PyRuntime.global_objects.NAME
7864
75.8k
    }
7865
432k
    else {
7866
432k
        stack[2] = value;
7867
432k
        res = vectorcall_method(&_Py_ID(__setattr__), stack, 3);
Line
Count
Source
374
432k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
432k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
432k
    _PyRuntime.global_objects.NAME
7868
432k
    }
7869
508k
    if (res == NULL)
  Branch (7869:9): [True: 329, False: 508k]
7870
329
        return -1;
7871
508k
    Py_DECREF(res);
Line
Count
Source
548
508k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
508k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
508k
#  define _Py_CAST(type, expr) ((type)(expr))
7872
508k
    return 0;
7873
508k
}
7874
7875
static PyObject *name_op[] = {
7876
    &_Py_ID(__lt__),
7877
    &_Py_ID(__le__),
7878
    &_Py_ID(__eq__),
7879
    &_Py_ID(__ne__),
7880
    &_Py_ID(__gt__),
7881
    &_Py_ID(__ge__),
7882
};
7883
7884
static PyObject *
7885
slot_tp_richcompare(PyObject *self, PyObject *other, int op)
7886
9.65M
{
7887
9.65M
    PyThreadState *tstate = _PyThreadState_GET();
7888
7889
9.65M
    int unbound;
7890
9.65M
    PyObject *func = lookup_maybe_method(self, name_op[op], &unbound);
7891
9.65M
    if (func == NULL) {
  Branch (7891:9): [True: 2, False: 9.65M]
7892
2
        PyErr_Clear();
7893
2
        Py_RETURN_NOTIMPLEMENTED;
Line
Count
Source
671
2
#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
Line
Count
Source
639
2
#  define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
Line
Count
Source
109
2
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2
#  define _Py_CAST(type, expr) ((type)(expr))
7894
2
    }
7895
7896
9.65M
    PyObject *stack[2] = {self, other};
7897
9.65M
    PyObject *res = vectorcall_unbound(tstate, unbound, func, stack, 2);
7898
9.65M
    Py_DECREF(func);
Line
Count
Source
548
9.65M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
9.65M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.65M
#  define _Py_CAST(type, expr) ((type)(expr))
7899
9.65M
    return res;
7900
9.65M
}
7901
7902
static PyObject *
7903
slot_tp_iter(PyObject *self)
7904
85.4k
{
7905
85.4k
    int unbound;
7906
85.4k
    PyObject *func, *res;
7907
7908
85.4k
    func = lookup_maybe_method(self, &_Py_ID(__iter__), &unbound);
Line
Count
Source
374
85.4k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
85.4k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
85.4k
    _PyRuntime.global_objects.NAME
7909
85.4k
    if (func == Py_None) {
Line
Count
Source
654
85.4k
#define Py_None (&_Py_NoneStruct)
  Branch (7909:9): [True: 28, False: 85.4k]
7910
28
        Py_DECREF(func);
Line
Count
Source
548
28
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
28
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
28
#  define _Py_CAST(type, expr) ((type)(expr))
7911
28
        PyErr_Format(PyExc_TypeError,
7912
28
                     "'%.200s' object is not iterable",
7913
28
                     Py_TYPE(self)->tp_name);
Line
Count
Source
138
28
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
28
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
28
#  define _Py_CAST(type, expr) ((type)(expr))
7914
28
        return NULL;
7915
28
    }
7916
7917
85.4k
    if (func != NULL) {
  Branch (7917:9): [True: 85.4k, False: 0]
7918
85.4k
        res = call_unbound_noarg(unbound, func, self);
7919
85.4k
        Py_DECREF(func);
Line
Count
Source
548
85.4k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
85.4k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
85.4k
#  define _Py_CAST(type, expr) ((type)(expr))
7920
85.4k
        return res;
7921
85.4k
    }
7922
7923
0
    PyErr_Clear();
7924
0
    func = lookup_maybe_method(self, &_Py_ID(__getitem__), &unbound);
Line
Count
Source
374
0
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
0
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
0
    _PyRuntime.global_objects.NAME
7925
0
    if (func == NULL) {
  Branch (7925:9): [True: 0, False: 0]
7926
0
        PyErr_Format(PyExc_TypeError,
7927
0
                     "'%.200s' object is not iterable",
7928
0
                     Py_TYPE(self)->tp_name);
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7929
0
        return NULL;
7930
0
    }
7931
0
    Py_DECREF(func);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7932
0
    return PySeqIter_New(self);
7933
0
}
7934
7935
static PyObject *
7936
slot_tp_iternext(PyObject *self)
7937
233k
{
7938
233k
    PyObject *stack[1] = {self};
7939
233k
    return vectorcall_method(&_Py_ID(__next__), stack, 1);
Line
Count
Source
374
233k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
233k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
233k
    _PyRuntime.global_objects.NAME
7940
233k
}
7941
7942
static PyObject *
7943
slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
7944
51.6k
{
7945
51.6k
    PyTypeObject *tp = Py_TYPE(self);
Line
Count
Source
138
51.6k
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
51.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
51.6k
#  define _Py_CAST(type, expr) ((type)(expr))
7946
51.6k
    PyObject *get;
7947
7948
51.6k
    get = _PyType_Lookup(tp, &_Py_ID(__get__));
Line
Count
Source
374
51.6k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
51.6k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
51.6k
    _PyRuntime.global_objects.NAME
7949
51.6k
    if (get == NULL) {
  Branch (7949:9): [True: 0, False: 51.6k]
7950
        /* Avoid further slowdowns */
7951
0
        if (tp->tp_descr_get == slot_tp_descr_get)
  Branch (7951:13): [True: 0, False: 0]
7952
0
            tp->tp_descr_get = NULL;
7953
0
        Py_INCREF(self);
Line
Count
Source
512
0
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
7954
0
        return self;
7955
0
    }
7956
51.6k
    if (obj == NULL)
  Branch (7956:9): [True: 34.3k, False: 17.2k]
7957
34.3k
        obj = Py_None;
Line
Count
Source
654
34.3k
#define Py_None (&_Py_NoneStruct)
7958
51.6k
    if (type == NULL)
  Branch (7958:9): [True: 0, False: 51.6k]
7959
0
        type = Py_None;
Line
Count
Source
654
0
#define Py_None (&_Py_NoneStruct)
7960
51.6k
    return PyObject_CallFunctionObjArgs(get, self, obj, type, NULL);
7961
51.6k
}
7962
7963
static int
7964
slot_tp_descr_set(PyObject *self, PyObject *target, PyObject *value)
7965
31
{
7966
31
    PyObject* stack[3];
7967
31
    PyObject *res;
7968
7969
31
    stack[0] = self;
7970
31
    stack[1] = target;
7971
31
    if (value == NULL) {
  Branch (7971:9): [True: 15, False: 16]
7972
15
        res = vectorcall_method(&_Py_ID(__delete__), stack, 2);
Line
Count
Source
374
15
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
15
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
15
    _PyRuntime.global_objects.NAME
7973
15
    }
7974
16
    else {
7975
16
        stack[2] = value;
7976
16
        res = vectorcall_method(&_Py_ID(__set__), stack, 3);
Line
Count
Source
374
16
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
16
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
16
    _PyRuntime.global_objects.NAME
7977
16
    }
7978
31
    if (res == NULL)
  Branch (7978:9): [True: 14, False: 17]
7979
14
        return -1;
7980
17
    Py_DECREF(res);
Line
Count
Source
548
17
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
17
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
17
#  define _Py_CAST(type, expr) ((type)(expr))
7981
17
    return 0;
7982
31
}
7983
7984
static int
7985
slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
7986
9.44M
{
7987
9.44M
    PyThreadState *tstate = _PyThreadState_GET();
7988
7989
9.44M
    int unbound;
7990
9.44M
    PyObject *meth = lookup_method(self, &_Py_ID(__init__), &unbound);
Line
Count
Source
374
9.44M
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
9.44M
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
9.44M
    _PyRuntime.global_objects.NAME
7991
9.44M
    if (meth == NULL) {
  Branch (7991:9): [True: 1, False: 9.44M]
7992
1
        return -1;
7993
1
    }
7994
7995
9.44M
    PyObject *res;
7996
9.44M
    if (unbound) {
  Branch (7996:9): [True: 9.44M, False: 2]
7997
9.44M
        res = _PyObject_Call_Prepend(tstate, meth, self, args, kwds);
7998
9.44M
    }
7999
2
    else {
8000
2
        res = _PyObject_Call(tstate, meth, args, kwds);
8001
2
    }
8002
9.44M
    Py_DECREF(meth);
Line
Count
Source
548
9.44M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
9.44M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.44M
#  define _Py_CAST(type, expr) ((type)(expr))
8003
9.44M
    if (res == NULL)
  Branch (8003:9): [True: 8.21k, False: 9.43M]
8004
8.21k
        return -1;
8005
9.43M
    if (res != Py_None) {
Line
Count
Source
654
9.43M
#define Py_None (&_Py_NoneStruct)
  Branch (8005:9): [True: 1, False: 9.43M]
8006
1
        PyErr_Format(PyExc_TypeError,
8007
1
                     "__init__() should return None, not '%.200s'",
8008
1
                     Py_TYPE(res)->tp_name);
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
8009
1
        Py_DECREF(res);
Line
Count
Source
548
1
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
8010
1
        return -1;
8011
1
    }
8012
9.43M
    Py_DECREF(res);
Line
Count
Source
548
9.43M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
9.43M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.43M
#  define _Py_CAST(type, expr) ((type)(expr))
8013
9.43M
    return 0;
8014
9.43M
}
8015
8016
static PyObject *
8017
slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
8018
3.05M
{
8019
3.05M
    PyThreadState *tstate = _PyThreadState_GET();
8020
3.05M
    PyObject *func, *result;
8021
8022
3.05M
    func = PyObject_GetAttr((PyObject *)type, &_Py_ID(__new__));
Line
Count
Source
374
3.05M
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
3.05M
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
3.05M
    _PyRuntime.global_objects.NAME
8023
3.05M
    if (func == NULL) {
  Branch (8023:9): [True: 0, False: 3.05M]
8024
0
        return NULL;
8025
0
    }
8026
8027
3.05M
    result = _PyObject_Call_Prepend(tstate, func, (PyObject *)type, args, kwds);
8028
3.05M
    Py_DECREF(func);
Line
Count
Source
548
3.05M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.05M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.05M
#  define _Py_CAST(type, expr) ((type)(expr))
8029
3.05M
    return result;
8030
3.05M
}
8031
8032
static void
8033
slot_tp_finalize(PyObject *self)
8034
75.0k
{
8035
75.0k
    int unbound;
8036
75.0k
    PyObject *del, *res;
8037
75.0k
    PyObject *error_type, *error_value, *error_traceback;
8038
8039
    /* Save the current exception, if any. */
8040
75.0k
    PyErr_Fetch(&error_type, &error_value, &error_traceback);
8041
8042
    /* Execute __del__ method, if any. */
8043
75.0k
    del = lookup_maybe_method(self, &_Py_ID(__del__), &unbound);
Line
Count
Source
374
75.0k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
75.0k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
75.0k
    _PyRuntime.global_objects.NAME
8044
75.0k
    if (del != NULL) {
  Branch (8044:9): [True: 75.0k, False: 0]
8045
75.0k
        res = call_unbound_noarg(unbound, del, self);
8046
75.0k
        if (res == NULL)
  Branch (8046:13): [True: 7, False: 75.0k]
8047
7
            PyErr_WriteUnraisable(del);
8048
75.0k
        else
8049
75.0k
            Py_DECREF(res);
Line
Count
Source
548
75.0k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
75.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
75.0k
#  define _Py_CAST(type, expr) ((type)(expr))
8050
75.0k
        Py_DECREF(del);
Line
Count
Source
548
75.0k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
75.0k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
75.0k
#  define _Py_CAST(type, expr) ((type)(expr))
8051
75.0k
    }
8052
8053
    /* Restore the saved exception. */
8054
75.0k
    PyErr_Restore(error_type, error_value, error_traceback);
8055
75.0k
}
8056
8057
static PyObject *
8058
slot_am_await(PyObject *self)
8059
221
{
8060
221
    int unbound;
8061
221
    PyObject *func, *res;
8062
8063
221
    func = lookup_maybe_method(self, &_Py_ID(__await__), &unbound);
Line
Count
Source
374
221
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
221
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
221
    _PyRuntime.global_objects.NAME
8064
221
    if (func != NULL) {
  Branch (8064:9): [True: 221, False: 0]
8065
221
        res = call_unbound_noarg(unbound, func, self);
8066
221
        Py_DECREF(func);
Line
Count
Source
548
221
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
221
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
221
#  define _Py_CAST(type, expr) ((type)(expr))
8067
221
        return res;
8068
221
    }
8069
0
    PyErr_Format(PyExc_AttributeError,
8070
0
                 "object %.50s does not have __await__ method",
8071
0
                 Py_TYPE(self)->tp_name);
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
8072
0
    return NULL;
8073
221
}
8074
8075
static PyObject *
8076
slot_am_aiter(PyObject *self)
8077
31
{
8078
31
    int unbound;
8079
31
    PyObject *func, *res;
8080
8081
31
    func = lookup_maybe_method(self, &_Py_ID(__aiter__), &unbound);
Line
Count
Source
374
31
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
31
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
31
    _PyRuntime.global_objects.NAME
8082
31
    if (func != NULL) {
  Branch (8082:9): [True: 31, False: 0]
8083
31
        res = call_unbound_noarg(unbound, func, self);
8084
31
        Py_DECREF(func);
Line
Count
Source
548
31
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
31
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
31
#  define _Py_CAST(type, expr) ((type)(expr))
8085
31
        return res;
8086
31
    }
8087
0
    PyErr_Format(PyExc_AttributeError,
8088
0
                 "object %.50s does not have __aiter__ method",
8089
0
                 Py_TYPE(self)->tp_name);
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
8090
0
    return NULL;
8091
31
}
8092
8093
static PyObject *
8094
slot_am_anext(PyObject *self)
8095
365
{
8096
365
    int unbound;
8097
365
    PyObject *func, *res;
8098
8099
365
    func = lookup_maybe_method(self, &_Py_ID(__anext__), &unbound);
Line
Count
Source
374
365
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
365
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
365
    _PyRuntime.global_objects.NAME
8100
365
    if (func != NULL) {
  Branch (8100:9): [True: 365, False: 0]
8101
365
        res = call_unbound_noarg(unbound, func, self);
8102
365
        Py_DECREF(func);
Line
Count
Source
548
365
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
365
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
365
#  define _Py_CAST(type, expr) ((type)(expr))
8103
365
        return res;
8104
365
    }
8105
0
    PyErr_Format(PyExc_AttributeError,
8106
0
                 "object %.50s does not have __anext__ method",
8107
0
                 Py_TYPE(self)->tp_name);
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
8108
0
    return NULL;
8109
365
}
8110
8111
/*
8112
Table mapping __foo__ names to tp_foo offsets and slot_tp_foo wrapper functions.
8113
8114
The table is ordered by offsets relative to the 'PyHeapTypeObject' structure,
8115
which incorporates the additional structures used for numbers, sequences and
8116
mappings.  Note that multiple names may map to the same slot (e.g. __eq__,
8117
__ne__ etc. all map to tp_richcompare) and one name may map to multiple slots
8118
(e.g. __str__ affects tp_str as well as tp_repr). The table is terminated with
8119
an all-zero entry.  (This table is further initialized in
8120
_PyTypes_InitSlotDefs().)
8121
*/
8122
8123
typedef struct wrapperbase slotdef;
8124
8125
#undef TPSLOT
8126
#undef FLSLOT
8127
#undef AMSLOT
8128
#undef ETSLOT
8129
#undef SQSLOT
8130
#undef MPSLOT
8131
#undef NBSLOT
8132
#undef UNSLOT
8133
#undef IBSLOT
8134
#undef BINSLOT
8135
#undef RBINSLOT
8136
8137
#define TPSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
8138
    {NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \
8139
     PyDoc_STR(DOC)}
8140
#define FLSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC, FLAGS) \
8141
    {NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \
8142
     PyDoc_STR(DOC), FLAGS}
8143
#define ETSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
8144
    {NAME, offsetof(PyHeapTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \
8145
     PyDoc_STR(DOC)}
8146
#define AMSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
8147
    ETSLOT(NAME, as_async.SLOT, FUNCTION, WRAPPER, DOC)
8148
#define SQSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
8149
    ETSLOT(NAME, as_sequence.SLOT, FUNCTION, WRAPPER, DOC)
8150
#define MPSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
8151
    ETSLOT(NAME, as_mapping.SLOT, FUNCTION, WRAPPER, DOC)
8152
#define NBSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
8153
    ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, DOC)
8154
#define UNSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
8155
    ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, \
8156
           NAME "($self, /)\n--\n\n" DOC)
8157
#define IBSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
8158
    ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, \
8159
           NAME "($self, value, /)\n--\n\nReturn self" DOC "value.")
8160
#define BINSLOT(NAME, SLOT, FUNCTION, DOC) \
8161
    ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_l, \
8162
           NAME "($self, value, /)\n--\n\nReturn self" DOC "value.")
8163
#define RBINSLOT(NAME, SLOT, FUNCTION, DOC) \
8164
    ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_r, \
8165
           NAME "($self, value, /)\n--\n\nReturn value" DOC "self.")
8166
#define BINSLOTNOTINFIX(NAME, SLOT, FUNCTION, DOC) \
8167
    ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_l, \
8168
           NAME "($self, value, /)\n--\n\n" DOC)
8169
#define RBINSLOTNOTINFIX(NAME, SLOT, FUNCTION, DOC) \
8170
    ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_r, \
8171
           NAME "($self, value, /)\n--\n\n" DOC)
8172
8173
static slotdef slotdefs[] = {
8174
    TPSLOT("__getattribute__", tp_getattr, NULL, NULL, ""),
8175
    TPSLOT("__getattr__", tp_getattr, NULL, NULL, ""),
8176
    TPSLOT("__setattr__", tp_setattr, NULL, NULL, ""),
8177
    TPSLOT("__delattr__", tp_setattr, NULL, NULL, ""),
8178
    TPSLOT("__repr__", tp_repr, slot_tp_repr, wrap_unaryfunc,
8179
           "__repr__($self, /)\n--\n\nReturn repr(self)."),
8180
    TPSLOT("__hash__", tp_hash, slot_tp_hash, wrap_hashfunc,
8181
           "__hash__($self, /)\n--\n\nReturn hash(self)."),
8182
    FLSLOT("__call__", tp_call, slot_tp_call, (wrapperfunc)(void(*)(void))wrap_call,
8183
           "__call__($self, /, *args, **kwargs)\n--\n\nCall self as a function.",
8184
           PyWrapperFlag_KEYWORDS),
8185
    TPSLOT("__str__", tp_str, slot_tp_str, wrap_unaryfunc,
8186
           "__str__($self, /)\n--\n\nReturn str(self)."),
8187
    TPSLOT("__getattribute__", tp_getattro, slot_tp_getattr_hook,
8188
           wrap_binaryfunc,
8189
           "__getattribute__($self, name, /)\n--\n\nReturn getattr(self, name)."),
8190
    TPSLOT("__getattr__", tp_getattro, slot_tp_getattr_hook, NULL, ""),
8191
    TPSLOT("__setattr__", tp_setattro, slot_tp_setattro, wrap_setattr,
8192
           "__setattr__($self, name, value, /)\n--\n\nImplement setattr(self, name, value)."),
8193
    TPSLOT("__delattr__", tp_setattro, slot_tp_setattro, wrap_delattr,
8194
           "__delattr__($self, name, /)\n--\n\nImplement delattr(self, name)."),
8195
    TPSLOT("__lt__", tp_richcompare, slot_tp_richcompare, richcmp_lt,
8196
           "__lt__($self, value, /)\n--\n\nReturn self<value."),
8197
    TPSLOT("__le__", tp_richcompare, slot_tp_richcompare, richcmp_le,
8198
           "__le__($self, value, /)\n--\n\nReturn self<=value."),
8199
    TPSLOT("__eq__", tp_richcompare, slot_tp_richcompare, richcmp_eq,
8200
           "__eq__($self, value, /)\n--\n\nReturn self==value."),
8201
    TPSLOT("__ne__", tp_richcompare, slot_tp_richcompare, richcmp_ne,
8202
           "__ne__($self, value, /)\n--\n\nReturn self!=value."),
8203
    TPSLOT("__gt__", tp_richcompare, slot_tp_richcompare, richcmp_gt,
8204
           "__gt__($self, value, /)\n--\n\nReturn self>value."),
8205
    TPSLOT("__ge__", tp_richcompare, slot_tp_richcompare, richcmp_ge,
8206
           "__ge__($self, value, /)\n--\n\nReturn self>=value."),
8207
    TPSLOT("__iter__", tp_iter, slot_tp_iter, wrap_unaryfunc,
8208
           "__iter__($self, /)\n--\n\nImplement iter(self)."),
8209
    TPSLOT("__next__", tp_iternext, slot_tp_iternext, wrap_next,
8210
           "__next__($self, /)\n--\n\nImplement next(self)."),
8211
    TPSLOT("__get__", tp_descr_get, slot_tp_descr_get, wrap_descr_get,
8212
           "__get__($self, instance, owner=None, /)\n--\n\nReturn an attribute of instance, which is of type owner."),
8213
    TPSLOT("__set__", tp_descr_set, slot_tp_descr_set, wrap_descr_set,
8214
           "__set__($self, instance, value, /)\n--\n\nSet an attribute of instance to value."),
8215
    TPSLOT("__delete__", tp_descr_set, slot_tp_descr_set,
8216
           wrap_descr_delete,
8217
           "__delete__($self, instance, /)\n--\n\nDelete an attribute of instance."),
8218
    FLSLOT("__init__", tp_init, slot_tp_init, (wrapperfunc)(void(*)(void))wrap_init,
8219
           "__init__($self, /, *args, **kwargs)\n--\n\n"
8220
           "Initialize self.  See help(type(self)) for accurate signature.",
8221
           PyWrapperFlag_KEYWORDS),
8222
    TPSLOT("__new__", tp_new, slot_tp_new, NULL,
8223
           "__new__(type, /, *args, **kwargs)\n--\n\n"
8224
           "Create and return new object.  See help(type) for accurate signature."),
8225
    TPSLOT("__del__", tp_finalize, slot_tp_finalize, (wrapperfunc)wrap_del, ""),
8226
8227
    AMSLOT("__await__", am_await, slot_am_await, wrap_unaryfunc,
8228
           "__await__($self, /)\n--\n\nReturn an iterator to be used in await expression."),
8229
    AMSLOT("__aiter__", am_aiter, slot_am_aiter, wrap_unaryfunc,
8230
           "__aiter__($self, /)\n--\n\nReturn an awaitable, that resolves in asynchronous iterator."),
8231
    AMSLOT("__anext__", am_anext, slot_am_anext, wrap_unaryfunc,
8232
           "__anext__($self, /)\n--\n\nReturn a value or raise StopAsyncIteration."),
8233
8234
    BINSLOT("__add__", nb_add, slot_nb_add,
8235
           "+"),
8236
    RBINSLOT("__radd__", nb_add, slot_nb_add,
8237
           "+"),
8238
    BINSLOT("__sub__", nb_subtract, slot_nb_subtract,
8239
           "-"),
8240
    RBINSLOT("__rsub__", nb_subtract, slot_nb_subtract,
8241
           "-"),
8242
    BINSLOT("__mul__", nb_multiply, slot_nb_multiply,
8243
           "*"),
8244
    RBINSLOT("__rmul__", nb_multiply, slot_nb_multiply,
8245
           "*"),
8246
    BINSLOT("__mod__", nb_remainder, slot_nb_remainder,
8247
           "%"),
8248
    RBINSLOT("__rmod__", nb_remainder, slot_nb_remainder,
8249
           "%"),
8250
    BINSLOTNOTINFIX("__divmod__", nb_divmod, slot_nb_divmod,
8251
           "Return divmod(self, value)."),
8252
    RBINSLOTNOTINFIX("__rdivmod__", nb_divmod, slot_nb_divmod,
8253
           "Return divmod(value, self)."),
8254
    NBSLOT("__pow__", nb_power, slot_nb_power, wrap_ternaryfunc,
8255
           "__pow__($self, value, mod=None, /)\n--\n\nReturn pow(self, value, mod)."),
8256
    NBSLOT("__rpow__", nb_power, slot_nb_power, wrap_ternaryfunc_r,
8257
           "__rpow__($self, value, mod=None, /)\n--\n\nReturn pow(value, self, mod)."),
8258
    UNSLOT("__neg__", nb_negative, slot_nb_negative, wrap_unaryfunc, "-self"),
8259
    UNSLOT("__pos__", nb_positive, slot_nb_positive, wrap_unaryfunc, "+self"),
8260
    UNSLOT("__abs__", nb_absolute, slot_nb_absolute, wrap_unaryfunc,
8261
           "abs(self)"),
8262
    UNSLOT("__bool__", nb_bool, slot_nb_bool, wrap_inquirypred,
8263
           "True if self else False"),
8264
    UNSLOT("__invert__", nb_invert, slot_nb_invert, wrap_unaryfunc, "~self"),
8265
    BINSLOT("__lshift__", nb_lshift, slot_nb_lshift, "<<"),
8266
    RBINSLOT("__rlshift__", nb_lshift, slot_nb_lshift, "<<"),
8267
    BINSLOT("__rshift__", nb_rshift, slot_nb_rshift, ">>"),
8268
    RBINSLOT("__rrshift__", nb_rshift, slot_nb_rshift, ">>"),
8269
    BINSLOT("__and__", nb_and, slot_nb_and, "&"),
8270
    RBINSLOT("__rand__", nb_and, slot_nb_and, "&"),
8271
    BINSLOT("__xor__", nb_xor, slot_nb_xor, "^"),
8272
    RBINSLOT("__rxor__", nb_xor, slot_nb_xor, "^"),
8273
    BINSLOT("__or__", nb_or, slot_nb_or, "|"),
8274
    RBINSLOT("__ror__", nb_or, slot_nb_or, "|"),
8275
    UNSLOT("__int__", nb_int, slot_nb_int, wrap_unaryfunc,
8276
           "int(self)"),
8277
    UNSLOT("__float__", nb_float, slot_nb_float, wrap_unaryfunc,
8278
           "float(self)"),
8279
    IBSLOT("__iadd__", nb_inplace_add, slot_nb_inplace_add,
8280
           wrap_binaryfunc, "+="),
8281
    IBSLOT("__isub__", nb_inplace_subtract, slot_nb_inplace_subtract,
8282
           wrap_binaryfunc, "-="),
8283
    IBSLOT("__imul__", nb_inplace_multiply, slot_nb_inplace_multiply,
8284
           wrap_binaryfunc, "*="),
8285
    IBSLOT("__imod__", nb_inplace_remainder, slot_nb_inplace_remainder,
8286
           wrap_binaryfunc, "%="),
8287
    IBSLOT("__ipow__", nb_inplace_power, slot_nb_inplace_power,
8288
           wrap_ternaryfunc, "**="),
8289
    IBSLOT("__ilshift__", nb_inplace_lshift, slot_nb_inplace_lshift,
8290
           wrap_binaryfunc, "<<="),
8291
    IBSLOT("__irshift__", nb_inplace_rshift, slot_nb_inplace_rshift,
8292
           wrap_binaryfunc, ">>="),
8293
    IBSLOT("__iand__", nb_inplace_and, slot_nb_inplace_and,
8294
           wrap_binaryfunc, "&="),
8295
    IBSLOT("__ixor__", nb_inplace_xor, slot_nb_inplace_xor,
8296
           wrap_binaryfunc, "^="),
8297
    IBSLOT("__ior__", nb_inplace_or, slot_nb_inplace_or,
8298
           wrap_binaryfunc, "|="),
8299
    BINSLOT("__floordiv__", nb_floor_divide, slot_nb_floor_divide, "//"),
8300
    RBINSLOT("__rfloordiv__", nb_floor_divide, slot_nb_floor_divide, "//"),
8301
    BINSLOT("__truediv__", nb_true_divide, slot_nb_true_divide, "/"),
8302
    RBINSLOT("__rtruediv__", nb_true_divide, slot_nb_true_divide, "/"),
8303
    IBSLOT("__ifloordiv__", nb_inplace_floor_divide,
8304
           slot_nb_inplace_floor_divide, wrap_binaryfunc, "//="),
8305
    IBSLOT("__itruediv__", nb_inplace_true_divide,
8306
           slot_nb_inplace_true_divide, wrap_binaryfunc, "/="),
8307
    NBSLOT("__index__", nb_index, slot_nb_index, wrap_unaryfunc,
8308
           "__index__($self, /)\n--\n\n"
8309
           "Return self converted to an integer, if self is suitable "
8310
           "for use as an index into a list."),
8311
    BINSLOT("__matmul__", nb_matrix_multiply, slot_nb_matrix_multiply,
8312
            "@"),
8313
    RBINSLOT("__rmatmul__", nb_matrix_multiply, slot_nb_matrix_multiply,
8314
             "@"),
8315
    IBSLOT("__imatmul__", nb_inplace_matrix_multiply, slot_nb_inplace_matrix_multiply,
8316
           wrap_binaryfunc, "@="),
8317
    MPSLOT("__len__", mp_length, slot_mp_length, wrap_lenfunc,
8318
           "__len__($self, /)\n--\n\nReturn len(self)."),
8319
    MPSLOT("__getitem__", mp_subscript, slot_mp_subscript,
8320
           wrap_binaryfunc,
8321
           "__getitem__($self, key, /)\n--\n\nReturn self[key]."),
8322
    MPSLOT("__setitem__", mp_ass_subscript, slot_mp_ass_subscript,
8323
           wrap_objobjargproc,
8324
           "__setitem__($self, key, value, /)\n--\n\nSet self[key] to value."),
8325
    MPSLOT("__delitem__", mp_ass_subscript, slot_mp_ass_subscript,
8326
           wrap_delitem,
8327
           "__delitem__($self, key, /)\n--\n\nDelete self[key]."),
8328
8329
    SQSLOT("__len__", sq_length, slot_sq_length, wrap_lenfunc,
8330
           "__len__($self, /)\n--\n\nReturn len(self)."),
8331
    /* Heap types defining __add__/__mul__ have sq_concat/sq_repeat == NULL.
8332
       The logic in abstract.c always falls back to nb_add/nb_multiply in
8333
       this case.  Defining both the nb_* and the sq_* slots to call the
8334
       user-defined methods has unexpected side-effects, as shown by
8335
       test_descr.notimplemented() */
8336
    SQSLOT("__add__", sq_concat, NULL, wrap_binaryfunc,
8337
           "__add__($self, value, /)\n--\n\nReturn self+value."),
8338
    SQSLOT("__mul__", sq_repeat, NULL, wrap_indexargfunc,
8339
           "__mul__($self, value, /)\n--\n\nReturn self*value."),
8340
    SQSLOT("__rmul__", sq_repeat, NULL, wrap_indexargfunc,
8341
           "__rmul__($self, value, /)\n--\n\nReturn value*self."),
8342
    SQSLOT("__getitem__", sq_item, slot_sq_item, wrap_sq_item,
8343
           "__getitem__($self, key, /)\n--\n\nReturn self[key]."),
8344
    SQSLOT("__setitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_setitem,
8345
           "__setitem__($self, key, value, /)\n--\n\nSet self[key] to value."),
8346
    SQSLOT("__delitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_delitem,
8347
           "__delitem__($self, key, /)\n--\n\nDelete self[key]."),
8348
    SQSLOT("__contains__", sq_contains, slot_sq_contains, wrap_objobjproc,
8349
           "__contains__($self, key, /)\n--\n\nReturn key in self."),
8350
    SQSLOT("__iadd__", sq_inplace_concat, NULL,
8351
           wrap_binaryfunc,
8352
           "__iadd__($self, value, /)\n--\n\nImplement self+=value."),
8353
    SQSLOT("__imul__", sq_inplace_repeat, NULL,
8354
           wrap_indexargfunc,
8355
           "__imul__($self, value, /)\n--\n\nImplement self*=value."),
8356
8357
    {NULL}
8358
};
8359
8360
/* Given a type pointer and an offset gotten from a slotdef entry, return a
8361
   pointer to the actual slot.  This is not quite the same as simply adding
8362
   the offset to the type pointer, since it takes care to indirect through the
8363
   proper indirection pointer (as_buffer, etc.); it returns NULL if the
8364
   indirection pointer is NULL. */
8365
static void **
8366
slotptr(PyTypeObject *type, int ioffset)
8367
18.0M
{
8368
18.0M
    char *ptr;
8369
18.0M
    long offset = ioffset;
8370
8371
    /* Note: this depends on the order of the members of PyHeapTypeObject! */
8372
18.0M
    assert(offset >= 0);
8373
18.0M
    assert((size_t)offset < offsetof(PyHeapTypeObject, as_buffer));
8374
18.0M
    if ((size_t)offset >= offsetof(PyHeapTypeObject, as_sequence)) {
  Branch (8374:9): [True: 2.01M, False: 16.0M]
8375
2.01M
        ptr = (char *)type->tp_as_sequence;
8376
2.01M
        offset -= offsetof(PyHeapTypeObject, as_sequence);
8377
2.01M
    }
8378
16.0M
    else if ((size_t)offset >= offsetof(PyHeapTypeObject, as_mapping)) {
  Branch (8378:14): [True: 785k, False: 15.2M]
8379
785k
        ptr = (char *)type->tp_as_mapping;
8380
785k
        offset -= offsetof(PyHeapTypeObject, as_mapping);
8381
785k
    }
8382
15.2M
    else if ((size_t)offset >= offsetof(PyHeapTypeObject, as_number)) {
  Branch (8382:14): [True: 9.06M, False: 6.15M]
8383
9.06M
        ptr = (char *)type->tp_as_number;
8384
9.06M
        offset -= offsetof(PyHeapTypeObject, as_number);
8385
9.06M
    }
8386
6.15M
    else if ((size_t)offset >= offsetof(PyHeapTypeObject, as_async)) {
  Branch (8386:14): [True: 615k, False: 5.54M]
8387
615k
        ptr = (char *)type->tp_as_async;
8388
615k
        offset -= offsetof(PyHeapTypeObject, as_async);
8389
615k
    }
8390
5.54M
    else {
8391
5.54M
        ptr = (char *)type;
8392
5.54M
    }
8393
18.0M
    if (ptr != NULL)
  Branch (8393:9): [True: 16.7M, False: 1.32M]
8394
16.7M
        ptr += offset;
8395
18.0M
    return (void **)ptr;
8396
18.0M
}
8397
8398
/* Length of array of slotdef pointers used to store slots with the
8399
   same __name__.  There should be at most MAX_EQUIV-1 slotdef entries with
8400
   the same __name__, for any __name__. Since that's a static property, it is
8401
   appropriate to declare fixed-size arrays for this. */
8402
#define MAX_EQUIV 10
8403
8404
/* Return a slot pointer for a given name, but ONLY if the attribute has
8405
   exactly one slot function.  The name must be an interned string. */
8406
static void **
8407
resolve_slotdups(PyTypeObject *type, PyObject *name)
8408
1.50M
{
8409
    /* XXX Maybe this could be optimized more -- but is it worth it? */
8410
8411
    /* pname and ptrs act as a little cache */
8412
1.50M
    static PyObject *pname;
8413
1.50M
    static slotdef *ptrs[MAX_EQUIV];
8414
1.50M
    slotdef *p, **pp;
8415
1.50M
    void **res, **ptr;
8416
8417
1.50M
    if (pname != name) {
  Branch (8417:9): [True: 1.50M, False: 5.86k]
8418
        /* Collect all slotdefs that match name into ptrs. */
8419
1.50M
        pname = name;
8420
1.50M
        pp = ptrs;
8421
139M
        for (p = slotdefs; p->name_strobj; p++) {
  Branch (8421:28): [True: 138M, False: 1.50M]
8422
138M
            if (p->name_strobj == name)
  Branch (8422:17): [True: 2.10M, False: 136M]
8423
2.10M
                *pp++ = p;
8424
138M
        }
8425
1.50M
        *pp = NULL;
8426
1.50M
    }
8427
8428
    /* Look in all slots of the type matching the name. If exactly one of these
8429
       has a filled-in slot, return a pointer to that slot.
8430
       Otherwise, return NULL. */
8431
1.50M
    res = NULL;
8432
3.57M
    for (pp = ptrs; *pp; pp++) {
  Branch (8432:21): [True: 2.10M, False: 1.46M]
8433
2.10M
        ptr = slotptr(type, (*pp)->offset);
8434
2.10M
        if (ptr == NULL || *ptr == NULL)
  Branch (8434:13): [True: 0, False: 2.10M]
  Branch (8434:28): [True: 647k, False: 1.46M]
8435
647k
            continue;
8436
1.46M
        if (res != NULL)
  Branch (8436:13): [True: 39.7k, False: 1.42M]
8437
39.7k
            return NULL;
8438
1.42M
        res = ptr;
8439
1.42M
    }
8440
1.46M
    return res;
8441
1.50M
}
8442
8443
8444
/* Common code for update_slots_callback() and fixup_slot_dispatchers().
8445
 *
8446
 * This is meant to set a "slot" like type->tp_repr or
8447
 * type->tp_as_sequence->sq_concat by looking up special methods like
8448
 * __repr__ or __add__. The opposite (adding special methods from slots) is
8449
 * done by add_operators(), called from PyType_Ready(). Since update_one_slot()
8450
 * calls PyType_Ready() if needed, the special methods are already in place.
8451
 *
8452
 * The special methods corresponding to each slot are defined in the "slotdef"
8453
 * array. Note that one slot may correspond to multiple special methods and vice
8454
 * versa. For example, tp_richcompare uses 6 methods __lt__, ..., __ge__ and
8455
 * tp_as_number->nb_add uses __add__ and __radd__. In the other direction,
8456
 * __add__ is used by the number and sequence protocols and __getitem__ by the
8457
 * sequence and mapping protocols. This causes a lot of complications.
8458
 *
8459
 * In detail, update_one_slot() does the following:
8460
 *
8461
 * First of all, if the slot in question does not exist, return immediately.
8462
 * This can happen for example if it's tp_as_number->nb_add but tp_as_number
8463
 * is NULL.
8464
 *
8465
 * For the given slot, we loop over all the special methods with a name
8466
 * corresponding to that slot (for example, for tp_descr_set, this would be
8467
 * __set__ and __delete__) and we look up these names in the MRO of the type.
8468
 * If we don't find any special method, the slot is set to NULL (regardless of
8469
 * what was in the slot before).
8470
 *
8471
 * Suppose that we find exactly one special method. If it's a wrapper_descriptor
8472
 * (i.e. a special method calling a slot, for example str.__repr__ which calls
8473
 * the tp_repr for the 'str' class) with the correct name ("__repr__" for
8474
 * tp_repr), for the right class, calling the right wrapper C function (like
8475
 * wrap_unaryfunc for tp_repr), then the slot is set to the slot that the
8476
 * wrapper_descriptor originally wrapped. For example, a class inheriting
8477
 * from 'str' and not redefining __repr__ will have tp_repr set to the tp_repr
8478
 * of 'str'.
8479
 * In all other cases where the special method exists, the slot is set to a
8480
 * wrapper calling the special method. There is one exception: if the special
8481
 * method is a wrapper_descriptor with the correct name but the type has
8482
 * precisely one slot set for that name and that slot is not the one that we
8483
 * are updating, then NULL is put in the slot (this exception is the only place
8484
 * in update_one_slot() where the *existing* slots matter).
8485
 *
8486
 * When there are multiple special methods for the same slot, the above is
8487
 * applied for each special method. As long as the results agree, the common
8488
 * resulting slot is applied. If the results disagree, then a wrapper for
8489
 * the special methods is installed. This is always safe, but less efficient
8490
 * because it uses method lookup instead of direct C calls.
8491
 *
8492
 * There are some further special cases for specific slots, like supporting
8493
 * __hash__ = None for tp_hash and special code for tp_new.
8494
 *
8495
 * When done, return a pointer to the next slotdef with a different offset,
8496
 * because that's convenient for fixup_slot_dispatchers(). This function never
8497
 * sets an exception: if an internal error happens (unlikely), it's ignored. */
8498
static slotdef *
8499
update_one_slot(PyTypeObject *type, slotdef *p)
8500
6.04M
{
8501
6.04M
    PyObject *descr;
8502
6.04M
    PyWrapperDescrObject *d;
8503
6.04M
    void *generic = NULL, *specific = NULL;
8504
6.04M
    int use_generic = 0;
8505
6.04M
    int offset = p->offset;
8506
6.04M
    int error;
8507
6.04M
    void **ptr = slotptr(type, offset);
8508
8509
6.04M
    if (ptr == NULL) {
  Branch (8509:9): [True: 0, False: 6.04M]
8510
0
        do {
8511
0
            ++p;
8512
0
        } while (p->offset == offset);
  Branch (8512:18): [True: 0, False: 0]
8513
0
        return p;
8514
0
    }
8515
    /* We may end up clearing live exceptions below, so make sure it's ours. */
8516
6.04M
    assert(!PyErr_Occurred());
8517
8.70M
    do {
8518
        /* Use faster uncached lookup as we won't get any cache hits during type setup. */
8519
8.70M
        descr = find_name_in_mro(type, p->name_strobj, &error);
8520
8.70M
        if (descr == NULL) {
  Branch (8520:13): [True: 6.33M, False: 2.37M]
8521
6.33M
            if (error == -1) {
  Branch (8521:17): [True: 0, False: 6.33M]
8522
                /* It is unlikely but not impossible that there has been an exception
8523
                   during lookup. Since this function originally expected no errors,
8524
                   we ignore them here in order to keep up the interface. */
8525
0
                PyErr_Clear();
8526
0
            }
8527
6.33M
            if (ptr == (void**)&type->tp_iternext) {
  Branch (8527:17): [True: 84.1k, False: 6.25M]
8528
84.1k
                specific = (void *)_PyObject_NextNotImplemented;
8529
84.1k
            }
8530
6.33M
            continue;
8531
6.33M
        }
8532
2.37M
        if (Py_IS_TYPE(descr, &PyWrapperDescr_Type) &&
Line
Count
Source
155
4.74M
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
2.37M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.37M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 1.51M, False: 862k]
8533
2.37M
            ((PyWrapperDescrObject *)descr)->d_base->name_strobj == p->name_strobj) {
  Branch (8533:13): [True: 1.50M, False: 1.21k]
8534
1.50M
            void **tptr = resolve_slotdups(type, p->name_strobj);
8535
1.50M
            if (tptr == NULL || tptr == ptr)
  Branch (8535:17): [True: 127k, False: 1.38M]
  Branch (8535:33): [True: 1.10M, False: 279k]
8536
1.22M
                generic = p->function;
8537
1.50M
            d = (PyWrapperDescrObject *)descr;
8538
1.50M
            if ((specific == NULL || specific == d->d_wrapped) &&
  Branch (8538:18): [True: 935k, False: 573k]
  Branch (8538:38): [True: 573k, False: 114]
8539
1.50M
                d->d_base->wrapper == p->wrapper &&
  Branch (8539:17): [True: 1.21M, False: 289k]
8540
1.50M
                PyType_IsSubtype(type, PyDescr_TYPE(d)))
Line
Count
Source
35
1.21M
#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
  Branch (8540:17): [True: 1.21M, False: 1]
8541
1.21M
            {
8542
1.21M
                specific = d->d_wrapped;
8543
1.21M
            }
8544
289k
            else {
8545
                /* We cannot use the specific slot function because either
8546
                   - it is not unique: there are multiple methods for this
8547
                     slot and they conflict
8548
                   - the signature is wrong (as checked by the ->wrapper
8549
                     comparison above)
8550
                   - it's wrapping the wrong class
8551
                 */
8552
289k
                use_generic = 1;
8553
289k
            }
8554
1.50M
        }
8555
863k
        else if (Py_IS_TYPE(descr, &PyCFunction_Type) &&
Line
Count
Source
155
1.72M
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
863k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
863k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (155:32): [True: 64.9k, False: 798k]
8556
863k
                 PyCFunction_GET_FUNCTION(descr) ==
Line
Count
Source
43
64.9k
#define PyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(_PyObject_CAST(func))
Line
Count
Source
109
64.9k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
64.9k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (8556:18): [True: 64.9k, False: 4]
8557
863k
                 _PyCFunction_CAST(tp_new_wrapper) &&
Line
Count
Source
46
64.9k
    _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
Line
Count
Source
71
928k
#  define _Py_CAST(type, expr) ((type)(expr))
8558
863k
                 ptr == (void**)&type->tp_new)
  Branch (8558:18): [True: 64.9k, False: 0]
8559
64.9k
        {
8560
            /* The __new__ wrapper is not a wrapper descriptor,
8561
               so must be special-cased differently.
8562
               If we don't do this, creating an instance will
8563
               always use slot_tp_new which will look up
8564
               __new__ in the MRO which will call tp_new_wrapper
8565
               which will look through the base classes looking
8566
               for a static base and call its tp_new (usually
8567
               PyType_GenericNew), after performing various
8568
               sanity checks and constructing a new argument
8569
               list.  Cut all that nonsense short -- this speeds
8570
               up instance creation tremendously. */
8571
64.9k
            specific = (void *)type->tp_new;
8572
            /* XXX I'm not 100% sure that there isn't a hole
8573
               in this reasoning that requires additional
8574
               sanity checks.  I'll buy the first person to
8575
               point out a bug in this reasoning a beer. */
8576
64.9k
        }
8577
798k
        else if (descr == Py_None &&
Line
Count
Source
654
1.59M
#define Py_None (&_Py_NoneStruct)
  Branch (8577:18): [True: 4.43k, False: 793k]
8578
798k
                 ptr == (void**)&type->tp_hash) {
  Branch (8578:18): [True: 4.35k, False: 81]
8579
            /* We specifically allow __hash__ to be set to None
8580
               to prevent inheritance of the default
8581
               implementation from object.__hash__ */
8582
4.35k
            specific = (void *)PyObject_HashNotImplemented;
8583
4.35k
        }
8584
793k
        else {
8585
793k
            use_generic = 1;
8586
793k
            generic = p->function;
8587
793k
        }
8588
8.70M
    } while ((++p)->offset == offset);
  Branch (8588:14): [True: 2.66M, False: 6.04M]
8589
6.04M
    if (specific && !use_generic)
  Branch (8589:9): [True: 799k, False: 5.24M]
  Branch (8589:21): [True: 741k, False: 58.4k]
8590
741k
        *ptr = specific;
8591
5.30M
    else
8592
5.30M
        *ptr = generic;
8593
6.04M
    return p;
8594
6.04M
}
8595
8596
/* In the type, update the slots whose slotdefs are gathered in the pp array.
8597
   This is a callback for update_subclasses(). */
8598
static int
8599
update_slots_callback(PyTypeObject *type, void *data)
8600
359k
{
8601
359k
    slotdef **pp = (slotdef **)data;
8602
768k
    for (; *pp; pp++) {
  Branch (8602:12): [True: 408k, False: 359k]
8603
408k
        update_one_slot(type, *pp);
8604
408k
    }
8605
359k
    return 0;
8606
359k
}
8607
8608
static int slotdefs_initialized = 0;
8609
/* Initialize the slotdefs table by adding interned string objects for the
8610
   names. */
8611
PyStatus
8612
_PyTypes_InitSlotDefs(void)
8613
107
{
8614
107
    if (slotdefs_initialized) {
  Branch (8614:9): [True: 0, False: 107]
8615
0
        return _PyStatus_OK();
Line
Count
Source
25
0
    (PyStatus){._type = _PyStatus_TYPE_OK,}
8616
0
    }
8617
8618
9.95k
    for (slotdef *p = slotdefs; p->name; p++) {
  Branch (8618:33): [True: 9.84k, False: 107]
8619
        /* Slots must be ordered by their offset in the PyHeapTypeObject. */
8620
9.84k
        assert(!p[1].name || p->offset <= p[1].offset);
8621
        /* bpo-40521: Interned strings are shared by all subinterpreters */
8622
9.84k
        p->name_strobj = PyUnicode_InternFromString(p->name);
8623
9.84k
        if (!p->name_strobj || !PyUnicode_CHECK_INTERNED(p->name_strobj)) {
Line
Count
Source
191
9.84k
#define PyUnicode_CHECK_INTERNED(op) PyUnicode_CHECK_INTERNED(_PyObject_CAST(op))
Line
Count
Source
109
9.84k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.84k
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (8623:13): [True: 0, False: 9.84k]
  Branch (8623:32): [True: 0, False: 9.84k]
8624
0
            return _PyStatus_NO_MEMORY();
Line
Count
Source
33
0
#define _PyStatus_NO_MEMORY() _PyStatus_ERR("memory allocation failed")
Line
Count
Source
28
0
    (PyStatus){ \
29
0
        ._type = _PyStatus_TYPE_ERROR, \
30
0
        .func = _PyStatus_GET_FUNC(), \
Line
Count
Source
21
0
#  define _PyStatus_GET_FUNC() __func__
31
0
        .err_msg = (ERR_MSG)}
8625
0
        }
8626
9.84k
    }
8627
107
    slotdefs_initialized = 1;
8628
107
    return _PyStatus_OK();
Line
Count
Source
25
107
    (PyStatus){._type = _PyStatus_TYPE_OK,}
8629
107
}
8630
8631
/* Undo _PyTypes_InitSlotDefs(), releasing the interned strings. */
8632
static void clear_slotdefs(void)
8633
103
{
8634
9.57k
    for (slotdef *p = slotdefs; p->name; p++) {
  Branch (8634:33): [True: 9.47k, False: 103]
8635
9.47k
        Py_CLEAR(p->name_strobj);
Line
Count
Source
587
9.47k
    do {                                        \
588
9.47k
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
9.47k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.47k
#  define _Py_CAST(type, expr) ((type)(expr))
589
9.47k
        if (_py_tmp != NULL) {                  \
  Branch (589:13): [True: 9.47k, False: 0]
590
9.47k
            (op) = NULL;                        \
591
9.47k
            Py_DECREF(_py_tmp);                 \
Line
Count
Source
548
9.47k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
9.47k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.47k
#  define _Py_CAST(type, expr) ((type)(expr))
592
9.47k
        }                                       \
593
9.47k
    } while (0)
  Branch (593:14): [Folded - Ignored]
8636
9.47k
    }
8637
103
    slotdefs_initialized = 0;
8638
103
}
8639
8640
/* Update the slots after assignment to a class (type) attribute. */
8641
static int
8642
update_slot(PyTypeObject *type, PyObject *name)
8643
428k
{
8644
428k
    slotdef *ptrs[MAX_EQUIV];
8645
428k
    slotdef *p;
8646
428k
    slotdef **pp;
8647
428k
    int offset;
8648
8649
428k
    assert(PyUnicode_CheckExact(name));
8650
428k
    assert(PyUnicode_CHECK_INTERNED(name));
8651
8652
428k
    assert(slotdefs_initialized);
8653
428k
    pp = ptrs;
8654
39.8M
    for (p = slotdefs; p->name; p++) {
  Branch (8654:24): [True: 39.3M, False: 428k]
8655
39.3M
        assert(PyUnicode_CheckExact(p->name_strobj));
8656
39.3M
        assert(PyUnicode_CheckExact(name));
8657
        /* bpo-40521: Using interned strings. */
8658
39.3M
        if (p->name_strobj == name) {
  Branch (8658:13): [True: 396k, False: 38.9M]
8659
396k
            *pp++ = p;
8660
396k
        }
8661
39.3M
    }
8662
428k
    *pp = NULL;
8663
824k
    for (pp = ptrs; *pp; pp++) {
  Branch (8663:21): [True: 396k, False: 428k]
8664
396k
        p = *pp;
8665
396k
        offset = p->offset;
8666
551k
        while (p > slotdefs && (p-1)->offset == offset)
  Branch (8666:16): [True: 551k, False: 186]
  Branch (8666:32): [True: 155k, False: 396k]
8667
155k
            --p;
8668
396k
        *pp = p;
8669
396k
    }
8670
428k
    if (ptrs[0] == NULL)
  Branch (8670:9): [True: 78.6k, False: 349k]
8671
78.6k
        return 0; /* Not an attribute that affects any slots */
8672
349k
    return update_subclasses(type, name,
8673
349k
                             update_slots_callback, (void *)ptrs);
8674
428k
}
8675
8676
/* Store the proper functions in the slot dispatches at class (type)
8677
   definition time, based upon which operations the class overrides in its
8678
   dict. */
8679
static void
8680
fixup_slot_dispatchers(PyTypeObject *type)
8681
86.7k
{
8682
86.7k
    assert(!PyErr_Occurred());
8683
86.7k
    assert(slotdefs_initialized);
8684
5.72M
    for (slotdef *p = slotdefs; p->name; ) {
  Branch (8684:33): [True: 5.63M, False: 86.7k]
8685
5.63M
        p = update_one_slot(type, p);
8686
5.63M
    }
8687
86.7k
}
8688
8689
static void
8690
update_all_slots(PyTypeObject* type)
8691
45
{
8692
45
    slotdef *p;
8693
8694
    /* Clear the VALID_VERSION flag of 'type' and all its subclasses. */
8695
45
    PyType_Modified(type);
8696
8697
45
    assert(slotdefs_initialized);
8698
4.18k
    for (p = slotdefs; p->name; p++) {
  Branch (8698:24): [True: 4.14k, False: 45]
8699
        /* update_slot returns int but can't actually fail */
8700
4.14k
        update_slot(type, p->name_strobj);
8701
4.14k
    }
8702
45
}
8703
8704
8705
/* Call __set_name__ on all attributes (including descriptors)
8706
  in a newly generated type */
8707
static int
8708
type_new_set_names(PyTypeObject *type)
8709
86.7k
{
8710
86.7k
    PyObject *names_to_set = PyDict_Copy(type->tp_dict);
8711
86.7k
    if (names_to_set == NULL) {
  Branch (8711:9): [True: 0, False: 86.7k]
8712
0
        return -1;
8713
0
    }
8714
8715
86.7k
    Py_ssize_t i = 0;
8716
86.7k
    PyObject *key, *value;
8717
685k
    while (PyDict_Next(names_to_set, &i, &key, &value)) {
  Branch (8717:12): [True: 599k, False: 86.7k]
8718
599k
        PyObject *set_name = _PyObject_LookupSpecial(value,
8719
599k
                                                     &_Py_ID(__set_name__));
Line
Count
Source
374
599k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
599k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
599k
    _PyRuntime.global_objects.NAME
8720
599k
        if (set_name == NULL) {
  Branch (8720:13): [True: 589k, False: 10.1k]
8721
589k
            if (PyErr_Occurred()) {
  Branch (8721:17): [True: 0, False: 589k]
8722
0
                goto error;
8723
0
            }
8724
589k
            continue;
8725
589k
        }
8726
8727
10.1k
        PyObject *res = PyObject_CallFunctionObjArgs(set_name, type, key, NULL);
8728
10.1k
        Py_DECREF(set_name);
Line
Count
Source
548
10.1k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
10.1k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10.1k
#  define _Py_CAST(type, expr) ((type)(expr))
8729
8730
10.1k
        if (res == NULL) {
  Branch (8730:13): [True: 12, False: 10.1k]
8731
12
            _PyErr_FormatFromCause(PyExc_RuntimeError,
8732
12
                "Error calling __set_name__ on '%.100s' instance %R "
8733
12
                "in '%.100s'",
8734
12
                Py_TYPE(value)->tp_name, key, type->tp_name);
Line
Count
Source
138
12
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
8735
12
            goto error;
8736
12
        }
8737
10.1k
        Py_DECREF(res);
Line
Count
Source
548
10.1k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
10.1k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
10.1k
#  define _Py_CAST(type, expr) ((type)(expr))
8738
10.1k
    }
8739
8740
86.7k
    Py_DECREF(names_to_set);
Line
Count
Source
548
86.7k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
86.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.7k
#  define _Py_CAST(type, expr) ((type)(expr))
8741
86.7k
    return 0;
8742
8743
12
error:
8744
12
    Py_DECREF(names_to_set);
Line
Count
Source
548
12
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
12
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
12
#  define _Py_CAST(type, expr) ((type)(expr))
8745
12
    return -1;
8746
86.7k
}
8747
8748
8749
/* Call __init_subclass__ on the parent of a newly generated type */
8750
static int
8751
type_new_init_subclass(PyTypeObject *type, PyObject *kwds)
8752
86.7k
{
8753
86.7k
    PyObject *args[2] = {(PyObject *)type, (PyObject *)type};
8754
86.7k
    PyObject *super = _PyObject_FastCall((PyObject *)&PySuper_Type, args, 2);
8755
86.7k
    if (super == NULL) {
  Branch (8755:9): [True: 1, False: 86.7k]
8756
1
        return -1;
8757
1
    }
8758
8759
86.7k
    PyObject *func = PyObject_GetAttr(super, &_Py_ID(__init_subclass__));
Line
Count
Source
374
86.7k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
86.7k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
86.7k
    _PyRuntime.global_objects.NAME
8760
86.7k
    Py_DECREF(super);
Line
Count
Source
548
86.7k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
86.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.7k
#  define _Py_CAST(type, expr) ((type)(expr))
8761
86.7k
    if (func == NULL) {
  Branch (8761:9): [True: 0, False: 86.7k]
8762
0
        return -1;
8763
0
    }
8764
8765
86.7k
    PyObject *result = PyObject_VectorcallDict(func, NULL, 0, kwds);
8766
86.7k
    Py_DECREF(func);
Line
Count
Source
548
86.7k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
86.7k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.7k
#  define _Py_CAST(type, expr) ((type)(expr))
8767
86.7k
    if (result == NULL) {
  Branch (8767:9): [True: 43, False: 86.6k]
8768
43
        return -1;
8769
43
    }
8770
8771
86.6k
    Py_DECREF(result);
Line
Count
Source
548
86.6k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
86.6k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86.6k
#  define _Py_CAST(type, expr) ((type)(expr))
8772
86.6k
    return 0;
8773
86.7k
}
8774
8775
8776
/* recurse_down_subclasses() and update_subclasses() are mutually
8777
   recursive functions to call a callback for all subclasses,
8778
   but refraining from recursing into subclasses that define 'attr_name'. */
8779
8780
static int
8781
update_subclasses(PyTypeObject *type, PyObject *attr_name,
8782
                  update_callback callback, void *data)
8783
359k
{
8784
359k
    if (callback(type, data) < 0) {
  Branch (8784:9): [True: 0, False: 359k]
8785
0
        return -1;
8786
0
    }
8787
359k
    return recurse_down_subclasses(type, attr_name, callback, data);
8788
359k
}
8789
8790
static int
8791
recurse_down_subclasses(PyTypeObject *type, PyObject *attr_name,
8792
                        update_callback callback, void *data)
8793
359k
{
8794
    // It is safe to use a borrowed reference because update_subclasses() is
8795
    // only used with update_slots_callback() which doesn't modify
8796
    // tp_subclasses.
8797
359k
    PyObject *subclasses = type->tp_subclasses;  // borrowed ref
8798
359k
    if (subclasses == NULL) {
  Branch (8798:9): [True: 355k, False: 3.49k]
8799
355k
        return 0;
8800
355k
    }
8801
3.49k
    assert(PyDict_CheckExact(subclasses));
8802
8803
3.49k
    Py_ssize_t i = 0;
8804
3.49k
    PyObject *ref;
8805
13.2k
    while (PyDict_Next(subclasses, &i, NULL, &ref)) {
  Branch (8805:12): [True: 9.79k, False: 3.49k]
8806
9.79k
        assert(PyWeakref_CheckRef(ref));
8807
9.79k
        PyObject *obj = PyWeakref_GET_OBJECT(ref);
Line
Count
Source
56
9.79k
#define PyWeakref_GET_OBJECT(ref) PyWeakref_GET_OBJECT(_PyObject_CAST(ref))
Line
Count
Source
109
9.79k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
9.79k
#  define _Py_CAST(type, expr) ((type)(expr))
8808
9.79k
        assert(obj != NULL);
8809
9.79k
        if (obj == Py_None) {
Line
Count
Source
654
9.79k
#define Py_None (&_Py_NoneStruct)
  Branch (8809:13): [True: 0, False: 9.79k]
8810
0
            continue;
8811
0
        }
8812
9.79k
        PyTypeObject *subclass = _PyType_CAST(obj);
Line
Count
Source
792
9.79k
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
9.79k
#  define _Py_CAST(type, expr) ((type)(expr))
8813
8814
        /* Avoid recursing down into unaffected classes */
8815
9.79k
        PyObject *dict = subclass->tp_dict;
8816
9.79k
        if (dict != NULL && PyDict_Check(dict)) {
Line
Count
Source
18
9.79k
                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
Line
Count
Source
782
9.79k
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 9.79k, False: 0]
  Branch (8816:13): [True: 9.79k, False: 0]
8817
9.79k
            int r = PyDict_Contains(dict, attr_name);
8818
9.79k
            if (r < 0) {
  Branch (8818:17): [True: 0, False: 9.79k]
8819
0
                return -1;
8820
0
            }
8821
9.79k
            if (r > 0) {
  Branch (8821:17): [True: 27, False: 9.77k]
8822
27
                continue;
8823
27
            }
8824
9.79k
        }
8825
8826
9.77k
        if (update_subclasses(subclass, attr_name, callback, data) < 0) {
  Branch (8826:13): [True: 0, False: 9.77k]
8827
0
            return -1;
8828
0
        }
8829
9.77k
    }
8830
3.49k
    return 0;
8831
3.49k
}
8832
8833
/* This function is called by PyType_Ready() to populate the type's
8834
   dictionary with method descriptors for function slots.  For each
8835
   function slot (like tp_repr) that's defined in the type, one or more
8836
   corresponding descriptors are added in the type's tp_dict dictionary
8837
   under the appropriate name (like __repr__).  Some function slots
8838
   cause more than one descriptor to be added (for example, the nb_add
8839
   slot adds both __add__ and __radd__ descriptors) and some function
8840
   slots compete for the same descriptor (for example both sq_item and
8841
   mp_subscript generate a __getitem__ descriptor).
8842
8843
   In the latter case, the first slotdef entry encountered wins.  Since
8844
   slotdef entries are sorted by the offset of the slot in the
8845
   PyHeapTypeObject, this gives us some control over disambiguating
8846
   between competing slots: the members of PyHeapTypeObject are listed
8847
   from most general to least general, so the most general slot is
8848
   preferred.  In particular, because as_mapping comes before as_sequence,
8849
   for a type that defines both mp_subscript and sq_item, mp_subscript
8850
   wins.
8851
8852
   This only adds new descriptors and doesn't overwrite entries in
8853
   tp_dict that were previously defined.  The descriptors contain a
8854
   reference to the C function they must call, so that it's safe if they
8855
   are copied into a subtype's __dict__ and the subtype has a different
8856
   C function in its slot -- calling the method defined by the
8857
   descriptor will call the C function that was used to create it,
8858
   rather than the C function present in the slot when it is called.
8859
   (This is important because a subtype may have a C function in the
8860
   slot that calls the method from the dictionary, and we want to avoid
8861
   infinite recursion here.) */
8862
8863
static int
8864
add_operators(PyTypeObject *type)
8865
114k
{
8866
114k
    PyObject *dict = type->tp_dict;
8867
114k
    slotdef *p;
8868
114k
    PyObject *descr;
8869
114k
    void **ptr;
8870
8871
114k
    assert(slotdefs_initialized);
8872
10.6M
    for (p = slotdefs; p->name; p++) {
  Branch (8872:24): [True: 10.5M, False: 114k]
8873
10.5M
        if (p->wrapper == NULL)
  Branch (8873:13): [True: 688k, False: 9.87M]
8874
688k
            continue;
8875
9.87M
        ptr = slotptr(type, p->offset);
8876
9.87M
        if (!ptr || !*ptr)
  Branch (8876:13): [True: 1.32M, False: 8.55M]
  Branch (8876:21): [True: 8.35M, False: 195k]
8877
9.67M
            continue;
8878
195k
        int r = PyDict_Contains(dict, p->name_strobj);
8879
195k
        if (r > 0)
  Branch (8879:13): [True: 2.70k, False: 192k]
8880
2.70k
            continue;
8881
192k
        if (r < 0) {
  Branch (8881:13): [True: 0, False: 192k]
8882
0
            return -1;
8883
0
        }
8884
192k
        if (*ptr == (void *)PyObject_HashNotImplemented) {
  Branch (8884:13): [True: 1.48k, False: 191k]
8885
            /* Classes may prevent the inheritance of the tp_hash
8886
               slot by storing PyObject_HashNotImplemented in it. Make it
8887
               visible as a None value for the __hash__ attribute. */
8888
1.48k
            if (PyDict_SetItem(dict, p->name_strobj, Py_None) < 0)
Line
Count
Source
654
1.48k
#define Py_None (&_Py_NoneStruct)
  Branch (8888:17): [True: 0, False: 1.48k]
8889
0
                return -1;
8890
1.48k
        }
8891
191k
        else {
8892
191k
            descr = PyDescr_NewWrapper(type, p, *ptr);
8893
191k
            if (descr == NULL)
  Branch (8893:17): [True: 0, False: 191k]
8894
0
                return -1;
8895
191k
            if (PyDict_SetItem(dict, p->name_strobj, descr) < 0) {
  Branch (8895:17): [True: 0, False: 191k]
8896
0
                Py_DECREF(descr);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
8897
0
                return -1;
8898
0
            }
8899
191k
            Py_DECREF(descr);
Line
Count
Source
548
191k
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
191k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
191k
#  define _Py_CAST(type, expr) ((type)(expr))
8900
191k
        }
8901
192k
    }
8902
114k
    return 0;
8903
114k
}
8904
8905
8906
/* Cooperative 'super' */
8907
8908
typedef struct {
8909
    PyObject_HEAD
8910
    PyTypeObject *type;
8911
    PyObject *obj;
8912
    PyTypeObject *obj_type;
8913
} superobject;
8914
8915
static PyMemberDef super_members[] = {
8916
    {"__thisclass__", T_OBJECT, offsetof(superobject, type), READONLY,
8917
     "the class invoking super()"},
8918
    {"__self__",  T_OBJECT, offsetof(superobject, obj), READONLY,
8919
     "the instance invoking super(); may be None"},
8920
    {"__self_class__", T_OBJECT, offsetof(superobject, obj_type), READONLY,
8921
     "the type of the instance invoking super(); may be None"},
8922
    {0}
8923
};
8924
8925
static void
8926
super_dealloc(PyObject *self)
8927
3.53M
{
8928
3.53M
    superobject *su = (superobject *)self;
8929
8930
3.53M
    _PyObject_GC_UNTRACK(self);
Line
Count
Source
187
3.53M
        _PyObject_GC_UNTRACK(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
8931
3.53M
    Py_XDECREF(su->obj);
Line
Count
Source
613
3.53M
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
8932
3.53M
    Py_XDECREF(su->type);
Line
Count
Source
613
3.53M
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
8933
3.53M
    Py_XDECREF(su->obj_type);
Line
Count
Source
613
3.53M
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
8934
3.53M
    Py_TYPE(self)->tp_free(self);
Line
Count
Source
138
3.53M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
8935
3.53M
}
8936
8937
static PyObject *
8938
super_repr(PyObject *self)
8939
0
{
8940
0
    superobject *su = (superobject *)self;
8941
8942
0
    if (su->obj_type)
  Branch (8942:9): [True: 0, False: 0]
8943
0
        return PyUnicode_FromFormat(
8944
0
            "<super: <class '%s'>, <%s object>>",
8945
0
            su->type ? su->type->tp_name : "NULL",
  Branch (8945:13): [True: 0, False: 0]
8946
0
            su->obj_type->tp_name);
8947
0
    else
8948
0
        return PyUnicode_FromFormat(
8949
0
            "<super: <class '%s'>, NULL>",
8950
0
            su->type ? su->type->tp_name : "NULL");
  Branch (8950:13): [True: 0, False: 0]
8951
0
}
8952
8953
static PyObject *
8954
super_getattro(PyObject *self, PyObject *name)
8955
3.53M
{
8956
3.53M
    superobject *su = (superobject *)self;
8957
3.53M
    PyTypeObject *starttype;
8958
3.53M
    PyObject *mro;
8959
3.53M
    Py_ssize_t i, n;
8960
8961
3.53M
    starttype = su->obj_type;
8962
3.53M
    if (starttype == NULL)
  Branch (8962:9): [True: 2, False: 3.53M]
8963
2
        goto skip;
8964
8965
    /* We want __class__ to return the class of the super object
8966
       (i.e. super, or a subclass), not the class of su->obj. */
8967
3.53M
    if (PyUnicode_Check(name) &&
Line
Count
Source
115
3.53M
    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
Line
Count
Source
782
7.06M
#define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
  Branch (782:41): [True: 3.53M, False: 0]
8968
3.53M
        PyUnicode_GET_LENGTH(name) == 9 &&
Line
Count
Source
275
3.53M
#define PyUnicode_GET_LENGTH(op) PyUnicode_GET_LENGTH(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (8968:9): [True: 82.5k, False: 3.45M]
8969
3.53M
        _PyUnicode_Equal(name, &_Py_ID(__class__)))
Line
Count
Source
374
82.5k
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
82.5k
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
82.5k
    _PyRuntime.global_objects.NAME
  Branch (8969:9): [True: 1, False: 82.5k]
8970
1
        goto skip;
8971
8972
3.53M
    mro = starttype->tp_mro;
8973
3.53M
    if (mro == NULL)
  Branch (8973:9): [True: 1, False: 3.53M]
8974
1
        goto skip;
8975
8976
3.53M
    assert(PyTuple_Check(mro));
8977
3.53M
    n = PyTuple_GET_SIZE(mro);
Line
Count
Source
26
3.53M
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
8978
8979
    /* No need to check the last one: it's gonna be skipped anyway.  */
8980
4.39M
    for (i = 0; i+1 < n; i++) {
  Branch (8980:17): [True: 4.39M, False: 1]
8981
4.39M
        if ((PyObject *)(su->type) == PyTuple_GET_ITEM(mro, i))
Line
Count
Source
28
4.39M
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
4.39M
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
4.39M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (8981:13): [True: 3.53M, False: 858k]
8982
3.53M
            break;
8983
4.39M
    }
8984
3.53M
    i++;  /* skip su->type (if any)  */
8985
3.53M
    if (i >= n)
  Branch (8985:9): [True: 1, False: 3.53M]
8986
1
        goto skip;
8987
8988
    /* keep a strong reference to mro because starttype->tp_mro can be
8989
       replaced during PyDict_GetItemWithError(dict, name)  */
8990
3.53M
    Py_INCREF(mro);
Line
Count
Source
512
3.53M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
8991
6.69M
    do {
8992
6.69M
        PyObject *obj = PyTuple_GET_ITEM(mro, i);
Line
Count
Source
28
6.69M
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
6.69M
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
6.69M
#  define _Py_CAST(type, expr) ((type)(expr))
8993
6.69M
        PyObject *dict = _PyType_CAST(obj)->tp_dict;
Line
Count
Source
792
6.69M
    (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
Line
Count
Source
71
6.69M
#  define _Py_CAST(type, expr) ((type)(expr))
8994
6.69M
        assert(dict != NULL && PyDict_Check(dict));
8995
8996
6.69M
        PyObject *res = PyDict_GetItemWithError(dict, name);
8997
6.69M
        if (res != NULL) {
  Branch (8997:13): [True: 3.53M, False: 3.15M]
8998
3.53M
            Py_INCREF(res);
Line
Count
Source
512
3.53M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
8999
9000
3.53M
            descrgetfunc f = Py_TYPE(res)->tp_descr_get;
Line
Count
Source
138
3.53M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
9001
3.53M
            if (f != NULL) {
  Branch (9001:17): [True: 2.74M, False: 785k]
9002
2.74M
                PyObject *res2;
9003
2.74M
                res2 = f(res,
9004
                    /* Only pass 'obj' param if this is instance-mode super
9005
                       (See SF ID #743627)  */
9006
2.74M
                    (su->obj == (PyObject *)starttype) ? NULL : su->obj,
  Branch (9006:21): [True: 90.2k, False: 2.65M]
9007
2.74M
                    (PyObject *)starttype);
9008
2.74M
                Py_DECREF(res);
Line
Count
Source
548
2.74M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
2.74M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.74M
#  define _Py_CAST(type, expr) ((type)(expr))
9009
2.74M
                res = res2;
9010
2.74M
            }
9011
9012
3.53M
            Py_DECREF(mro);
Line
Count
Source
548
3.53M
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
9013
3.53M
            return res;
9014
3.53M
        }
9015
3.15M
        else if (PyErr_Occurred()) {
  Branch (9015:18): [True: 0, False: 3.15M]
9016
0
            Py_DECREF(mro);
Line
Count
Source
548
0
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
9017
0
            return NULL;
9018
0
        }
9019
9020
3.15M
        i++;
9021
3.15M
    } while (i < n);
  Branch (9021:14): [True: 3.15M, False: 86]
9022
86
    Py_DECREF(mro);
Line
Count
Source
548
86
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
86
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
86
#  define _Py_CAST(type, expr) ((type)(expr))
9023
9024
91
  skip:
9025
91
    return PyObject_GenericGetAttr(self, name);
9026
86
}
9027
9028
static PyTypeObject *
9029
supercheck(PyTypeObject *type, PyObject *obj)
9030
3.53M
{
9031
    /* Check that a super() call makes sense.  Return a type object.
9032
9033
       obj can be a class, or an instance of one:
9034
9035
       - If it is a class, it must be a subclass of 'type'.      This case is
9036
         used for class methods; the return value is obj.
9037
9038
       - If it is an instance, it must be an instance of 'type'.  This is
9039
         the normal case; the return value is obj.__class__.
9040
9041
       But... when obj is an instance, we want to allow for the case where
9042
       Py_TYPE(obj) is not a subclass of type, but obj.__class__ is!
9043
       This will allow using super() with a proxy for obj.
9044
    */
9045
9046
    /* Check for first bullet above (special case) */
9047
3.53M
    if (PyType_Check(obj) && PyType_IsSubtype((PyTypeObject *)obj, type)) {
Line
Count
Source
788
7.06M
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (788:28): [True: 936k, False: 2.59M]
  Branch (9047:30): [True: 875k, False: 61.2k]
9048
875k
        Py_INCREF(obj);
Line
Count
Source
512
875k
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
875k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
875k
#  define _Py_CAST(type, expr) ((type)(expr))
9049
875k
        return (PyTypeObject *)obj;
9050
875k
    }
9051
9052
    /* Normal case */
9053
2.65M
    if (PyType_IsSubtype(Py_TYPE(obj), type)) {
Line
Count
Source
138
2.65M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.65M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.65M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (9053:9): [True: 2.65M, False: 7]
9054
2.65M
        Py_INCREF(Py_TYPE(obj));
Line
Count
Source
512
2.65M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
2.65M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.65M
#  define _Py_CAST(type, expr) ((type)(expr))
9055
2.65M
        return Py_TYPE(obj);
Line
Count
Source
138
2.65M
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
2.65M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.65M
#  define _Py_CAST(type, expr) ((type)(expr))
9056
2.65M
    }
9057
7
    else {
9058
        /* Try the slow way */
9059
7
        PyObject *class_attr;
9060
9061
7
        if (_PyObject_LookupAttr(obj, &_Py_ID(__class__), &class_attr) < 0) {
Line
Count
Source
374
7
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
7
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
7
    _PyRuntime.global_objects.NAME
  Branch (9061:13): [True: 0, False: 7]
9062
0
            return NULL;
9063
0
        }
9064
7
        if (class_attr != NULL &&
  Branch (9064:13): [True: 7, False: 0]
9065
7
            PyType_Check(class_attr) &&
Line
Count
Source
788
14
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
7
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (788:28): [True: 7, False: 0]
9066
7
            (PyTypeObject *)class_attr != Py_TYPE(obj))
Line
Count
Source
138
7
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
7
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
7
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (9066:13): [True: 1, False: 6]
9067
1
        {
9068
1
            int ok = PyType_IsSubtype(
9069
1
                (PyTypeObject *)class_attr, type);
9070
1
            if (ok) {
  Branch (9070:17): [True: 1, False: 0]
9071
1
                return (PyTypeObject *)class_attr;
9072
1
            }
9073
1
        }
9074
6
        Py_XDECREF(class_attr);
Line
Count
Source
613
6
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
6
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
6
#  define _Py_CAST(type, expr) ((type)(expr))
9075
6
    }
9076
9077
6
    PyErr_SetString(PyExc_TypeError,
9078
6
                    "super(type, obj): "
9079
6
                    "obj must be an instance or subtype of type");
9080
6
    return NULL;
9081
2.65M
}
9082
9083
static PyObject *
9084
super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
9085
16
{
9086
16
    superobject *su = (superobject *)self;
9087
16
    superobject *newobj;
9088
9089
16
    if (obj == NULL || obj == Py_None || su->obj != NULL) {
Line
Count
Source
654
32
#define Py_None (&_Py_NoneStruct)
  Branch (9089:9): [True: 0, False: 16]
  Branch (9089:24): [True: 0, False: 16]
  Branch (9089:42): [True: 0, False: 16]
9090
        /* Not binding to an object, or already bound */
9091
0
        Py_INCREF(self);
Line
Count
Source
512
0
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
9092
0
        return self;
9093
0
    }
9094
16
    if (!Py_IS_TYPE(su, &PySuper_Type))
Line
Count
Source
155
16
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
16
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
16
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (9094:9): [True: 1, False: 15]
9095
        /* If su is an instance of a (strict) subclass of super,
9096
           call its type */
9097
1
        return PyObject_CallFunctionObjArgs((PyObject *)Py_TYPE(su),
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
9098
1
                                            su->type, obj, NULL);
9099
15
    else {
9100
        /* Inline the common case */
9101
15
        PyTypeObject *obj_type = supercheck(su->type, obj);
9102
15
        if (obj_type == NULL)
  Branch (9102:13): [True: 2, False: 13]
9103
2
            return NULL;
9104
13
        newobj = (superobject *)PySuper_Type.tp_new(&PySuper_Type,
9105
13
                                                 NULL, NULL);
9106
13
        if (newobj == NULL)
  Branch (9106:13): [True: 0, False: 13]
9107
0
            return NULL;
9108
13
        Py_INCREF(su->type);
Line
Count
Source
512
13
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
13
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13
#  define _Py_CAST(type, expr) ((type)(expr))
9109
13
        Py_INCREF(obj);
Line
Count
Source
512
13
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
13
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
13
#  define _Py_CAST(type, expr) ((type)(expr))
9110
13
        newobj->type = su->type;
9111
13
        newobj->obj = obj;
9112
13
        newobj->obj_type = obj_type;
9113
13
        return (PyObject *)newobj;
9114
13
    }
9115
16
}
9116
9117
static int
9118
super_init_without_args(_PyInterpreterFrame *cframe, PyCodeObject *co,
9119
                        PyTypeObject **type_p, PyObject **obj_p)
9120
2.37M
{
9121
2.37M
    if (co->co_argcount == 0) {
  Branch (9121:9): [True: 1, False: 2.37M]
9122
1
        PyErr_SetString(PyExc_RuntimeError,
9123
1
                        "super(): no arguments");
9124
1
        return -1;
9125
1
    }
9126
9127
2.37M
    assert(cframe->f_code->co_nlocalsplus > 0);
9128
2.37M
    PyObject *firstarg = _PyFrame_GetLocalsArray(cframe)[0];
9129
    // The first argument might be a cell.
9130
2.37M
    if (firstarg != NULL && (_PyLocals_GetKind(co->co_localspluskinds, 0) & CO_FAST_CELL)) {
Line
Count
Source
143
2.37M
#define CO_FAST_CELL    0x40
  Branch (9130:9): [True: 2.37M, False: 1]
  Branch (9130:29): [True: 1.09k, False: 2.37M]
9131
        // "firstarg" is a cell here unless (very unlikely) super()
9132
        // was called from the C-API before the first MAKE_CELL op.
9133
1.09k
        if (_PyInterpreterFrame_LASTI(cframe) >= 0) {
Line
Count
Source
71
1.09k
    ((int)((IF)->prev_instr - _PyCode_CODE((IF)->f_code)))
Line
Count
Source
145
1.09k
#define _PyCode_CODE(CO) ((_Py_CODEUNIT *)(CO)->co_code_adaptive)
  Branch (9133:13): [True: 1.09k, False: 0]
9134
            // MAKE_CELL and COPY_FREE_VARS have no quickened forms, so no need
9135
            // to use _PyOpcode_Deopt here:
9136
1.09k
            assert(_Py_OPCODE(_PyCode_CODE(co)[0]) == MAKE_CELL ||
9137
1.09k
                   _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS);
9138
1.09k
            assert(PyCell_Check(firstarg));
9139
1.09k
            firstarg = PyCell_GET(firstarg);
Line
Count
Source
30
1.09k
#define PyCell_GET(op) PyCell_GET(_PyObject_CAST(op))
Line
Count
Source
109
1.09k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.09k
#  define _Py_CAST(type, expr) ((type)(expr))
9140
1.09k
        }
9141
1.09k
    }
9142
2.37M
    if (firstarg == NULL) {
  Branch (9142:9): [True: 1, False: 2.37M]
9143
1
        PyErr_SetString(PyExc_RuntimeError,
9144
1
                        "super(): arg[0] deleted");
9145
1
        return -1;
9146
1
    }
9147
9148
    // Look for __class__ in the free vars.
9149
2.37M
    PyTypeObject *type = NULL;
9150
2.37M
    int i = co->co_nlocals + co->co_nplaincellvars;
9151
2.37M
    for (; i < co->co_nlocalsplus; i++) {
  Branch (9151:12): [True: 2.37M, False: 0]
9152
2.37M
        assert((_PyLocals_GetKind(co->co_localspluskinds, i) & CO_FAST_FREE) != 0);
9153
2.37M
        PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i);
Line
Count
Source
28
2.37M
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
Line
Count
Source
18
2.37M
    (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
Line
Count
Source
71
2.37M
#  define _Py_CAST(type, expr) ((type)(expr))
9154
2.37M
        assert(PyUnicode_Check(name));
9155
2.37M
        if (_PyUnicode_Equal(name, &_Py_ID(__class__))) {
Line
Count
Source
374
2.37M
     (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
Line
Count
Source
26
2.37M
    _Py_GLOBAL_OBJECT(singletons.NAME)
Line
Count
Source
24
2.37M
    _PyRuntime.global_objects.NAME
  Branch (9155:13): [True: 2.37M, False: 7]
9156
2.37M
            PyObject *cell = _PyFrame_GetLocalsArray(cframe)[i];
9157
2.37M
            if (cell == NULL || !PyCell_Check(cell)) {
Line
Count
Source
18
2.37M
#define PyCell_Check(op) Py_IS_TYPE((op), &PyCell_Type)
Line
Count
Source
155
2.37M
#  define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
Line
Count
Source
109
2.37M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.37M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (9157:17): [True: 0, False: 2.37M]
  Branch (9157:33): [True: 0, False: 2.37M]
9158
0
                PyErr_SetString(PyExc_RuntimeError,
9159
0
                  "super(): bad __class__ cell");
9160
0
                return -1;
9161
0
            }
9162
2.37M
            type = (PyTypeObject *) PyCell_GET(cell);
Line
Count
Source
30
2.37M
#define PyCell_GET(op) PyCell_GET(_PyObject_CAST(op))
Line
Count
Source
109
2.37M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.37M
#  define _Py_CAST(type, expr) ((type)(expr))
9163
2.37M
            if (type == NULL) {
  Branch (9163:17): [True: 1, False: 2.37M]
9164
1
                PyErr_SetString(PyExc_RuntimeError,
9165
1
                  "super(): empty __class__ cell");
9166
1
                return -1;
9167
1
            }
9168
2.37M
            if (!PyType_Check(type)) {
Line
Count
Source
788
2.37M
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
2.37M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.37M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (9168:17): [True: 0, False: 2.37M]
9169
0
                PyErr_Format(PyExc_RuntimeError,
9170
0
                  "super(): __class__ is not a type (%s)",
9171
0
                  Py_TYPE(type)->tp_name);
Line
Count
Source
138
0
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
0
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
0
#  define _Py_CAST(type, expr) ((type)(expr))
9172
0
                return -1;
9173
0
            }
9174
2.37M
            break;
9175
2.37M
        }
9176
2.37M
    }
9177
2.37M
    if (type == NULL) {
  Branch (9177:9): [True: 0, False: 2.37M]
9178
0
        PyErr_SetString(PyExc_RuntimeError,
9179
0
                        "super(): __class__ cell not found");
9180
0
        return -1;
9181
0
    }
9182
9183
2.37M
    *type_p = type;
9184
2.37M
    *obj_p = firstarg;
9185
2.37M
    return 0;
9186
2.37M
}
9187
9188
static int super_init_impl(PyObject *self, PyTypeObject *type, PyObject *obj);
9189
9190
static int
9191
super_init(PyObject *self, PyObject *args, PyObject *kwds)
9192
1.00k
{
9193
1.00k
    PyTypeObject *type = NULL;
9194
1.00k
    PyObject *obj = NULL;
9195
9196
1.00k
    if (!_PyArg_NoKeywords("super", kwds))
Line
Count
Source
31
1.00k
    ((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs)))
  Branch (31:6): [True: 1.00k, False: 0]
  Branch (31:26): [True: 0, False: 0]
9197
0
        return -1;
9198
1.00k
    if (!PyArg_ParseTuple(args, "|O!O:super", &PyType_Type, &type, &obj))
  Branch (9198:9): [True: 0, False: 1.00k]
9199
0
        return -1;
9200
1.00k
    if (super_init_impl(self, type, obj) < 0) {
  Branch (9200:9): [True: 0, False: 1.00k]
9201
0
        return -1;
9202
0
    }
9203
1.00k
    return 0;
9204
1.00k
}
9205
9206
static inline int
9207
3.53M
super_init_impl(PyObject *self, PyTypeObject *type, PyObject *obj) {
9208
3.53M
    superobject *su = (superobject *)self;
9209
3.53M
    PyTypeObject *obj_type = NULL;
9210
3.53M
    if (type == NULL) {
  Branch (9210:9): [True: 2.37M, False: 1.15M]
9211
        /* Call super(), without args -- fill in from __class__
9212
           and first local variable on the stack. */
9213
2.37M
        PyThreadState *tstate = _PyThreadState_GET();
9214
2.37M
        _PyInterpreterFrame *cframe = tstate->cframe->current_frame;
9215
2.37M
        if (cframe == NULL) {
  Branch (9215:13): [True: 0, False: 2.37M]
9216
0
            PyErr_SetString(PyExc_RuntimeError,
9217
0
                            "super(): no current frame");
9218
0
            return -1;
9219
0
        }
9220
2.37M
        int res = super_init_without_args(cframe, cframe->f_code, &type, &obj);
9221
9222
2.37M
        if (res < 0) {
  Branch (9222:13): [True: 3, False: 2.37M]
9223
3
            return -1;
9224
3
        }
9225
2.37M
    }
9226
9227
3.53M
    if (obj == Py_None)
Line
Count
Source
654
3.53M
#define Py_None (&_Py_NoneStruct)
  Branch (9227:9): [True: 0, False: 3.53M]
9228
0
        obj = NULL;
9229
3.53M
    if (obj != NULL) {
  Branch (9229:9): [True: 3.53M, False: 14]
9230
3.53M
        obj_type = supercheck(type, obj);
9231
3.53M
        if (obj_type == NULL)
  Branch (9231:13): [True: 4, False: 3.53M]
9232
4
            return -1;
9233
3.53M
        Py_INCREF(obj);
Line
Count
Source
512
3.53M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
9234
3.53M
    }
9235
3.53M
    Py_INCREF(type);
Line
Count
Source
512
3.53M
#  define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
9236
3.53M
    Py_XSETREF(su->type, type);
Line
Count
Source
339
3.53M
    do {                                        \
340
3.53M
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
341
3.53M
        (op) = (op2);                           \
342
3.53M
        Py_XDECREF(_py_tmp);                    \
Line
Count
Source
613
3.53M
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
343
3.53M
    } while (0)
  Branch (343:14): [Folded - Ignored]
9237
3.53M
    Py_XSETREF(su->obj, obj);
Line
Count
Source
339
3.53M
    do {                                        \
340
3.53M
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
341
3.53M
        (op) = (op2);                           \
342
3.53M
        Py_XDECREF(_py_tmp);                    \
Line
Count
Source
613
3.53M
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
343
3.53M
    } while (0)
  Branch (343:14): [Folded - Ignored]
9238
3.53M
    Py_XSETREF(su->obj_type, obj_type);
Line
Count
Source
339
3.53M
    do {                                        \
340
3.53M
        PyObject *_py_tmp = _PyObject_CAST(op); \
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
341
3.53M
        (op) = (op2);                           \
342
3.53M
        Py_XDECREF(_py_tmp);                    \
Line
Count
Source
613
3.53M
#  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
Line
Count
Source
109
3.53M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
3.53M
#  define _Py_CAST(type, expr) ((type)(expr))
343
3.53M
    } while (0)
  Branch (343:14): [Folded - Ignored]
9239
3.53M
    return 0;
9240
3.53M
}
9241
9242
PyDoc_STRVAR(super_doc,
9243
"super() -> same as super(__class__, <first argument>)\n"
9244
"super(type) -> unbound super object\n"
9245
"super(type, obj) -> bound super object; requires isinstance(obj, type)\n"
9246
"super(type, type2) -> bound super object; requires issubclass(type2, type)\n"
9247
"Typical use to call a cooperative superclass method:\n"
9248
"class C(B):\n"
9249
"    def meth(self, arg):\n"
9250
"        super().meth(arg)\n"
9251
"This works for class methods too:\n"
9252
"class C(B):\n"
9253
"    @classmethod\n"
9254
"    def cmeth(cls, arg):\n"
9255
"        super().cmeth(arg)\n");
9256
9257
static int
9258
super_traverse(PyObject *self, visitproc visit, void *arg)
9259
2.11k
{
9260
2.11k
    superobject *su = (superobject *)self;
9261
9262
2.11k
    Py_VISIT(su->obj);
Line
Count
Source
198
2.11k
    do {                                                                \
199
2.11k
        if (op) {                                                       \
  Branch (199:13): [True: 2.09k, False: 22]
200
2.09k
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
2.09k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.09k
#  define _Py_CAST(type, expr) ((type)(expr))
201
2.09k
            if (vret)                                                   \
  Branch (201:17): [True: 0, False: 2.09k]
202
2.09k
                return vret;                                            \
203
2.09k
        }                                                               \
204
2.11k
    } while (0)
  Branch (204:14): [Folded - Ignored]
9263
2.11k
    Py_VISIT(su->type);
Line
Count
Source
198
2.11k
    do {                                                                \
199
2.11k
        if (op) {                                                       \
  Branch (199:13): [True: 2.11k, False: 0]
200
2.11k
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
2.11k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.11k
#  define _Py_CAST(type, expr) ((type)(expr))
201
2.11k
            if (vret)                                                   \
  Branch (201:17): [True: 0, False: 2.11k]
202
2.11k
                return vret;                                            \
203
2.11k
        }                                                               \
204
2.11k
    } while (0)
  Branch (204:14): [Folded - Ignored]
9264
2.11k
    Py_VISIT(su->obj_type);
Line
Count
Source
198
2.11k
    do {                                                                \
199
2.11k
        if (op) {                                                       \
  Branch (199:13): [True: 2.09k, False: 22]
200
2.09k
            int vret = visit(_PyObject_CAST(op), arg);                  \
Line
Count
Source
109
2.09k
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
2.09k
#  define _Py_CAST(type, expr) ((type)(expr))
201
2.09k
            if (vret)                                                   \
  Branch (201:17): [True: 0, False: 2.09k]
202
2.09k
                return vret;                                            \
203
2.09k
        }                                                               \
204
2.11k
    } while (0)
  Branch (204:14): [Folded - Ignored]
9265
9266
2.11k
    return 0;
9267
2.11k
}
9268
9269
static PyObject *
9270
super_vectorcall(PyObject *self, PyObject *const *args,
9271
    size_t nargsf, PyObject *kwnames)
9272
3.53M
{
9273
3.53M
    assert(PyType_Check(self));
9274
3.53M
    if (!_PyArg_NoKwnames("super", kwnames)) {
Line
Count
Source
33
3.53M
    ((kwnames) == NULL || _PyArg_NoKwnames((funcname), (kwnames)))
  Branch (33:6): [True: 3.53M, False: 1]
  Branch (33:27): [True: 0, False: 1]
9275
1
        return NULL;
9276
1
    }
9277
3.53M
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
9278
3.53M
    if (!_PyArg_CheckPositional("super()", nargs, 0, 2)) {
Line
Count
Source
43
3.53M
    ((!_Py_ANY_VARARGS(max) && (min) <= (nargs) && (nargs) <= (max)) \
Line
Count
Source
37
7.06M
#define _Py_ANY_VARARGS(n) ((n) == PY_SSIZE_T_MAX)
Line
Count
Source
180
3.53M
#   define PY_SSIZE_T_MAX SSIZE_MAX
  Branch (43:7): [Folded - Ignored]
  Branch (43:32): [True: 3.53M, False: 0]
  Branch (43:52): [True: 3.53M, False: 1]
44
3.53M
     || _PyArg_CheckPositional((funcname), (nargs), (min), (max)))
  Branch (44:9): [True: 0, False: 1]
9279
1
        return NULL;
9280
1
    }
9281
3.53M
    PyTypeObject *type = NULL;
9282
3.53M
    PyObject *obj = NULL;
9283
3.53M
    PyTypeObject *self_type = (PyTypeObject *)self;
9284
3.53M
    PyObject *su = self_type->tp_alloc(self_type, 0);
9285
3.53M
    if (su == NULL) {
  Branch (9285:9): [True: 0, False: 3.53M]
9286
0
        return NULL;
9287
0
    }
9288
    // 1 or 2 argument form super().
9289
3.53M
    if (nargs != 0) {
  Branch (9289:9): [True: 1.15M, False: 2.37M]
9290
1.15M
        PyObject *arg0 = args[0];
9291
1.15M
        if (!PyType_Check(arg0)) {
Line
Count
Source
788
1.15M
#  define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
Line
Count
Source
109
1.15M
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1.15M
#  define _Py_CAST(type, expr) ((type)(expr))
  Branch (9291:13): [True: 1, False: 1.15M]
9292
1
            PyErr_Format(PyExc_TypeError,
9293
1
                "super() argument 1 must be a type, not %.200s", Py_TYPE(arg0)->tp_name);
Line
Count
Source
138
1
#  define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
Line
Count
Source
109
1
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
1
#  define _Py_CAST(type, expr) ((type)(expr))
9294
1
            goto fail;
9295
1
        }
9296
1.15M
        type = (PyTypeObject *)arg0;
9297
1.15M
    }
9298
3.53M
    if (nargs == 2) {
  Branch (9298:9): [True: 1.15M, False: 2.37M]
9299
1.15M
        obj = args[1];
9300
1.15M
    }
9301
3.53M
    if (super_init_impl(su, type, obj) < 0) {
  Branch (9301:9): [True: 7, False: 3.53M]
9302
7
        goto fail;
9303
7
    }
9304
3.53M
    return su;
9305
8
fail:
9306
8
    Py_DECREF(su);
Line
Count
Source
548
8
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
Line
Count
Source
109
8
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
Line
Count
Source
71
8
#  define _Py_CAST(type, expr) ((type)(expr))
9307
8
    return NULL;
9308
3.53M
}
9309
9310
PyTypeObject PySuper_Type = {
9311
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
9312
    "super",                                    /* tp_name */
9313
    sizeof(superobject),                        /* tp_basicsize */
9314
    0,                                          /* tp_itemsize */
9315
    /* methods */
9316
    super_dealloc,                              /* tp_dealloc */
9317
    0,                                          /* tp_vectorcall_offset */
9318
    0,                                          /* tp_getattr */
9319
    0,                                          /* tp_setattr */
9320
    0,                                          /* tp_as_async */
9321
    super_repr,                                 /* tp_repr */
9322
    0,                                          /* tp_as_number */
9323
    0,                                          /* tp_as_sequence */
9324
    0,                                          /* tp_as_mapping */
9325
    0,                                          /* tp_hash */
9326
    0,                                          /* tp_call */
9327
    0,                                          /* tp_str */
9328
    super_getattro,                             /* tp_getattro */
9329
    0,                                          /* tp_setattro */
9330
    0,                                          /* tp_as_buffer */
9331
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
9332
        Py_TPFLAGS_BASETYPE,                    /* tp_flags */
9333
    super_doc,                                  /* tp_doc */
9334
    super_traverse,                             /* tp_traverse */
9335
    0,                                          /* tp_clear */
9336
    0,                                          /* tp_richcompare */
9337
    0,                                          /* tp_weaklistoffset */
9338
    0,                                          /* tp_iter */
9339
    0,                                          /* tp_iternext */
9340
    0,                                          /* tp_methods */
9341
    super_members,                              /* tp_members */
9342
    0,                                          /* tp_getset */
9343
    0,                                          /* tp_base */
9344
    0,                                          /* tp_dict */
9345
    super_descr_get,                            /* tp_descr_get */
9346
    0,                                          /* tp_descr_set */
9347
    0,                                          /* tp_dictoffset */
9348
    super_init,                                 /* tp_init */
9349
    PyType_GenericAlloc,                        /* tp_alloc */
9350
    PyType_GenericNew,                          /* tp_new */
9351
    PyObject_GC_Del,                            /* tp_free */
9352
    .tp_vectorcall = (vectorcallfunc)super_vectorcall,
9353
};